nodemon: 'ts-node' is not recognized as an internal or external command
nodemon ./src/index.ts
[nodemon] 2.0.14
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: ts,json
[nodemon] starting ts-node ./src/index.ts
‘ts-node’ is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting…
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 10
- Comments: 16 (3 by maintainers)
Links to this issue
Commits related to this issue
- fix: use platform-specific separator when augmenting PATH Fixes: #1951 — committed to lorenzodallavecchia/nodemon by lorenzodallavecchia 2 years ago
- fix: use platform-specific separator when augmenting PATH Fixes: #1951 — committed to lorenzodallavecchia/nodemon by lorenzodallavecchia 2 years ago
In order to fix this issue, you could install ts-node globally :
npm install -g ts-nodehttps://stackoverflow.com/questions/44764004/ts-node-is-not-recognized-as-an-internal-or-external-command-operable-program
I have the same problem. Trying different ways to solve this issue i found a solution creating a new file in the root directory for the config of nodemon. Now i can be able to run my project without any problem
The config file called nodemon.json have this inside:
And in my package.json, my dev script call the config file for nodemon like this:
"dev": "nodemon --config nodemon.json index.ts",For the moment, that works for me, but i will try to find a different way to implement nodemon, without having the necessity of create a config file to call it.
I investigated the issue and found the root cause.
The problem occurs because of these lines in
run.js.This is pre-pending the local
.bindirectory to the PATH, so that locally installed packages may be found.When using
npm run, npm itself is already doing this, pre-pending the correct.bindirectories to the path.In
npm@6the incoming PATH looks like this.From
npm@7, the first part (node-gyp-bin) is no longer passed.nodemon is modifying the incoming
PATHvariable but using the wrong path separator:(on Windows it would be;). The result is that the prepended path “corrupts” the first element in the incomingPATHvariable, which innpm@7and later happens to be the local.bindirectory. The childcmdshell is spawned without the local.bindirectory in its lookup path, so it cannot find the local executables (likets-node).I cannot contribute a fix right now, but the solutions should be simple. Just use
path.delimiterinstead of hard-coding:.🎉 This issue has been resolved in version 2.0.16 🎉
The release is available on:
Your semantic-release bot 📦🚀
This works for me. Using the last line and replacing ‘src/main.ts’ with my targeted file works for now.
Same issue here.
Package.json:
Calling Nodemon:
Calling ts-node:
@abonvicini It’s working because you are not using
ts-nodebut thets-node/registerregister with node.So you can have the same approach without a configuration file:
In my case I have:
Another workaround is to target directly the ts-node executable with node in
nodemon.json:Or you can target :
"ts": "./node_modules/.bin/ts-node")"ts": "./node_modules/.bin/ts-node.cmd")"ts": "./node_modules/.bin/ts-node.ps1") Which all does more or less the same thing, except it’s platform specificI see this same problem and will just chime in with my testing/experience if its helpful.
I can confirm the same problem exists on Windows using npm version 7 and 8. I attempted it with a
git-bashshell,PowerShelland a good ol’cmdshell.Reverting back to npm 6 does resolve the issue for me. Meaning,
nodemonfindsts-nodethat is installed locally and executes it.Also, I sometimes use WSL. I tested this with WSL2 running Ubuntu 20.04. Using the latest npm (8.1.3)
nodemonworks as expected withts-node.So it appears to me to be an issue with
npm >= 7on Windows. I wonder if its a known breaking change or a bug. I didn’t research that.(Note: I do a clean install of the
node_modulesbetween each of these tests)