'babel-node is not recognized as an internal or external command, operable program or batch file
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.
Solution 1:[1]
you can try install babel's global version
npm install -g babel-cli
Solution 2:[2]
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
Solution 3:[3]
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.
Solution 4:[4]
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.
Solution 5:[5]
Adding npx
to the command might help, so exact binary will be executed
nodemon --exec npx babel-node src/index.js
Solution 6:[6]
For me the issue was solved by installing 'babel-node' globally by running this command:
npm install @babel/node -g
Solution 7:[7]
If your project is based on babel 7, you should run this
npm install @babel/cli @babel/core
Solution 8:[8]
install @babel/node , i came across the same problem and by installing this solved my problem
Solution 9:[9]
To intall babel packages worked for me
npm i @babel/cli @babel/core @babel/node @babel/preset-env --save-dev
Solution 10:[10]
"nodemon --exec ./node_modules/.bin/babel-node src/index.js"
Solution 11:[11]
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
Solution 12:[12]
My issue solved by running this command
> npx babel-watch .
Solution 13:[13]
you can also use
"start": "babel-node backend/server.js"
Solution 14:[14]
For those who struggle making it work for node + nodemon, what helped me was:
- Install these deps:
"@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"
- You can leave path to babel-node to be relative.
"dev": "nodemon src/index.js --exec babel-node",
Solution 15:[15]
This fixed it for me:
npm ci
(npm clean install removes node modules and then installs them again)
Solution 16:[16]
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"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow