[NODEMON]- babel-node not recognized as internal or external command

11k views Asked by At

I am trying to setup a simple express server. I am using nodemon to start my development server But my app keeps crashing because it does not recognize the "babel-node" command.

The error output is

[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,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...

my package.json scripts are

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "startdev": "nodemon --ext js,json  --exec babel-node index.js",
    "start": "babel-node index.js"
  }

and my dependencies and dev dependencies are

"dependencies": {
    "express": "^4.17.1",
    "express-graphql": "^0.12.0",
    "graphql": "^15.4.0",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@babel/cli": "^7.12.10",
    "@babel/core": "^7.12.10",
    "@babel/node": "^7.12.10",
    "@babel/plugin-proposal-object-rest-spread": "^7.12.1",
    "@babel/preset-env": "^7.12.11",
    "nodemon": "^2.0.7"
  }

I tried testing it without nodemon, by using the regular node command and it runs as expected


$ npm run start

> [email protected] start
> babel-node index.js

Server is up...

My folder strucher is below

enter image description here

the contents of index.js are

const express = require("express");


const app = express();

app.listen(() => {
    console.log("Server is up...")
})

I have also tried deleting my node_modules and package-lock.json files and reinstalling but still crashes.

3

There are 3 answers

5
Apoorva Chikara On

Remove your node_modules and follow these steps:

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

Then, check the existence of these files:

node_modules/.bin/babel-node

node_modules/.bin/babel-node.cmd - windows only

node_modules/@babel/node/bin/babel-node.js

If everything looks good add to package.json:

"start": "nodemon --exec babel-node index.js",
0
Boris Torrejon On

I ran into the same problem and solved it this way:

"scripts": {
    "start": "babel-node src/index.js",
    "dev"  : "nodemon --exec npm start"
  }

In the terminal run

npm run dev
0
Daniel Tkach On

None of the steps above work for me. I resorted to using yarn instead. Delete your package-lock.json Then do: yarn This will add the dependencies, then you can run it, most likely with yarn run dev (of course this depends on your scripts on package.json).