babel-node is not recognized as an internal or external command, operable program or batch file
Asked Answered
M

19

37

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.

Marimaria answered 2/2, 2017 at 11:29 Comment(1)
Installing the babel-CLI as globally npm install -g babel-cliMisreckon
S
33

you can try install babel's global version

npm install -g babel-cli
Servais answered 26/4, 2019 at 7:50 Comment(0)
P
24

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

Paripinnate answered 23/1, 2021 at 13:47 Comment(4)
I'm suspecting that line is from a scripts definition section in package.json file; am I right?Tagmemic
Latest version 7.13 does seem to require an absolute path, this change fixed it for me as wellKellar
Yeah happened to me today after updating npm not sure why. But this fixes my issue.Cleruchy
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...Frolicsome
T
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.

Toper answered 28/6, 2017 at 9:56 Comment(2)
I believe this is a typo and O.O. meant npm install babel-cliAleurone
outdated module. can we use @babel/cli ?Adrenal
E
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.

Electrostatics answered 20/9, 2020 at 13:52 Comment(0)
B
10

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

nodemon --exec npx babel-node src/index.js
Babb answered 6/8, 2021 at 11:33 Comment(0)
E
8

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

npm install @babel/node -g
Embassy answered 8/6, 2021 at 3:5 Comment(1)
You can also install it locally in the project, that would be better for most casesSappington
I
5

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

npm install  @babel/cli @babel/core

Ignacia answered 10/6, 2020 at 12:38 Comment(0)
G
3

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

Goforth answered 6/9, 2020 at 19:22 Comment(1)
Not worked for me, only worked installing babel-cliKnot
A
2

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
Antilles answered 3/1, 2021 at 6:55 Comment(0)
R
2

To intall babel packages worked for me

npm i @babel/cli @babel/core @babel/node @babel/preset-env --save-dev
Rimrock answered 21/9, 2021 at 14:54 Comment(0)
T
2

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

Tergiversate answered 30/1, 2022 at 19:53 Comment(2)
"start": "nodemon --exec ./node_modules/.bin/babel-node src/server.js",Tergiversate
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.Stereotropism
S
1

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",
Sappington answered 10/7, 2021 at 20:34 Comment(1)
I just had to install @babel/node and @babel/core globally to resolve the issue. My package.json looks like this: "devDependencies": { "babel": "^6.23.0", "babel-cli": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-env": "^1.6.1", "babel-register": "^6.26.0", "webpack": "^3.10.0", "webpack-dev-server": "^2.11.1" },Gawky
D
0

My issue solved by running this command

> npx babel-watch .
Deborahdeborath answered 22/1, 2021 at 10:22 Comment(0)
K
0

you can also use

"start": "babel-node backend/server.js"
Kutzer answered 23/5, 2021 at 16:39 Comment(0)
G
0

This fixed it for me:

npm ci

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

Guillaume answered 3/11, 2021 at 18:20 Comment(0)
W
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"
}
Warfarin answered 5/5, 2022 at 3:33 Comment(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.Squamosal
D
0

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 🔥

Displume answered 18/8, 2022 at 17:31 Comment(0)
R
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)

Rondi answered 15/11, 2022 at 11:40 Comment(0)
H
0

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.

Harmonyharmotome answered 24/1 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.