33

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.

1
  • Installing the babel-CLI as globally npm install -g babel-cli Sep 2, 2021 at 19:18

18 Answers 18

30

you can try install babel's global version

npm install -g babel-cli
22

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

4
  • I'm suspecting that line is from a scripts definition section in package.json file; am I right?
    – cueedee
    Jan 23, 2021 at 14:18
  • Latest version 7.13 does seem to require an absolute path, this change fixed it for me as well
    –  dandmcd
    Mar 24, 2021 at 1:33
  • Yeah happened to me today after updating npm not sure why. But this fixes my issue.
    – Gary Ong
    Mar 24, 2021 at 7:09
  • If you could plz update the answer to say where exactly you have included that line of code, that would be helpful, thanks! 😊 So future readers don't have to go into the comments to get that vital info... Apr 5, 2021 at 11:23
15

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.

2
  • I believe this is a typo and O.O. meant npm install babel-cli
    – user6068326
    Nov 27, 2017 at 5:02
  • outdated module. can we use @babel/cli ?
    – Udhaya
    Aug 27, 2019 at 1:14
10

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.

9

Adding npx to the command might help, so exact binary will be executed

nodemon --exec npx babel-node src/index.js
7

For me the issue was solved by installing 'babel-node' globally by running this command:

npm install @babel/node -g
1
  • You can also install it locally in the project, that would be better for most cases Jul 10, 2021 at 20:35
5

If your project is based on babel 7, you should run this

npm install  @babel/cli @babel/core

3

install @babel/node , i came across the same problem and by installing this solved my problem

1
  • Not worked for me, only worked installing babel-cli Dec 15, 2020 at 21:31
2

To intall babel packages worked for me

npm i @babel/cli @babel/core @babel/node @babel/preset-env --save-dev
2

"nodemon --exec ./node_modules/.bin/babel-node src/index.js"

2
  • "start": "nodemon --exec ./node_modules/.bin/babel-node src/server.js",
    – Luis
    Jan 30, 2022 at 19:58
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 31, 2022 at 9:14
1

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
0

My issue solved by running this command

> npx babel-watch .
0

you can also use

"start": "babel-node backend/server.js"
0

For those who struggle making it work for node + nodemon, what helped me was:

  1. 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"
  1. You can leave path to babel-node to be relative.
"dev": "nodemon src/index.js --exec babel-node",
0

This fixed it for me:

npm ci

(npm clean install removes node modules and then installs them again)

0

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"
}
1
  • So basically you were requesting a specific relative path for you babel executable that didn't exist. And after removing that relative path and just executing the babel from PATH it worked.
    – user643011
    May 5, 2022 at 22:47
0

yes i also get this error it was resolved do check 👇

 $ npm run dev

server@1.0.0 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

server@1.0.0 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 🔥

0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.