Reputation: 748
When I try to run a JS file by babel command it is showing:
"babel-node is not recognized as an internal or external command, operable program or batch file".
I had created 1.js
file in this written "console.log("hello world")"
;
and tried to run with babel-node command but it is showing the above-mentioned error.
Upvotes: 37
Views: 76000
Reputation: 2087
On some 'locked down' windows servers installing babel will not automatically update the PATH. In this case you need to manually add the npm path to you PATH environment variable.
In my case npm was installed at: C:\Users\myusername\AppData\Roaming\npm
Once the path was updated I could verify babel is working by typing babel --version from the command line to verify the correct version is reported and the error message is no longer displayed.
Upvotes: 0
Reputation: 2820
Confirm that you have these dependencies at a minimum in your package.json:
"dependencies": {
"@babel/core": "7.13.10",
"@babel/node": "7.13.12",
"@babel/preset-env": "7.13.12",
..
},
"devDependencies": {
"nodemon": "2.0.7",
...
}
Then check what script you are running. If you see the problem when running npm run dev
and you have something like:
"scripts": {
"dev": "nodemon --exec babel-node ./src/server.js",
..
},
Update your scripts to the following (assuming you don't already have a "start"):
"scripts": {
"start": "babel-node ./src/server.js",
"dev": "nodemon --exec npm start",
...
},
Basically, nodeman
is used during dev to hot reload code changes. babel-node
itself runs the server, but the issue being faced occurs when installed package is not detected by nodeman.
Although installing @babel/cli
globally, might appear to resolve the issue, it's not needed (and frowned upon: https://babeljs.io/docs/en/babel-cli)
Upvotes: 0
Reputation: 13
yes i also get this error it was resolved do check 👇
$ npm run dev
[email protected] dev nodemon --exec babel-node index
[nodemon] 2.0.15
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting babel-node index.js
'babel-node' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
after that I install nodemon globally then it was resolved.
$ npm install -g nodemon
added 2 packages, removed 85 packages, changed 30 packages, and audited 33 packages in 9s
3 packages are looking for funding
run npm fund
for details
found 0 vulnerabilities
result was ✅🔥
👇👍✅
$ npm run dev
[email protected] dev nodemon --exec babel-node index
[nodemon] 2.0.19
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting babel-node index.js
Server is runing 🔥
Upvotes: 0
Reputation: 11
After trying everything here, it still didn't work. Eventually I got it working by removing the folders containing the executable (which for me was node_modules/.bin/).
Before:
"scripts": {
"babel": "node_modules/.bin/babel src/index.js -o dist/assets/bundle.js"
}
After:
"scripts": {
"babel": "babel src/index.js -o dist/assets/bundle.js"
}
Upvotes: 0
Reputation: 1
This fixed it for me:
npm ci
(npm clean install removes node modules and then installs them again)
Upvotes: 0
Reputation: 651
To intall babel packages worked for me
npm i @babel/cli @babel/core @babel/node @babel/preset-env --save-dev
Upvotes: 2
Reputation: 615
Adding npx
to the command might help, so exact binary will be executed
nodemon --exec npx babel-node src/index.js
Upvotes: 11
Reputation: 638
For those who struggle making it work for node + nodemon, what helped me was:
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.6",
"@babel/node": "^7.14.7",
"@babel/preset-env": "^7.14.7",
"nodemon": "^2.0.12"
"dev": "nodemon src/index.js --exec babel-node",
Upvotes: 1
Reputation: 81
For me the issue was solved by installing 'babel-node' globally by running this command:
npm install @babel/node -g
Upvotes: 8
Reputation: 241
Tried many suggestions and finally, I had to explicitly provide the absolute path to babel-node to get it working in scripts definition section in package.json file.
"start": "nodemon --exec ./node_modules/.bin/babel-node src/index.js"
node - v15.5.1 nodemon - v2.0.7 @babel/node - v7.12.10
Upvotes: 24
Reputation: 9649
What is currently missing is part of @babel/node
. Depending on your project dependency you can install:
npm install @babel/cli
npm install @babel/node
Upvotes: 2
Reputation: 8635
a combination of above solutions worked for me:
npm install @babel/node
npm install @babel/cli
npm install @babel/core
and then I ran npm start
and it worked.
Upvotes: 10
Reputation: 39
install @babel/node , i came across the same problem and by installing this solved my problem
Upvotes: 3
Reputation: 431
If your project is based on babel 7, you should run this
npm install @babel/cli @babel/core
Upvotes: 5
Reputation: 1086
you can try install babel's global version
npm install -g babel-cli
Upvotes: 34
Reputation: 868
Make sure that you have got the babel module so that it can be used.
For example by using npm install babel-cli
to get a node_modules folder.
Then you can find the runnable in node_module/.bin.
Upvotes: 15