Why nodemon fail when using -- exec babel-node?

Viewed 3863

I have installed the bable-cli and the babel-preset-env, after installing nodemon the npm start fail to load my application when using the following in the package.json file:

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

Showing the following error:

[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node src/index.js`
'"node"' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...

But everything works fine when using the following:

"scripts": {
    "start": "babel-node src/index.js"
  }

Thanks!

2 Answers

I ran into the same problem and solved it this way: "scripts": { "start": "babel-node src/index.js" "dev" : "nodemon --exec npm start" }

The reason is because you are not sending anything to babel to transpire and run. nodemon just looks for file changes.

Try this instead.

"serve":nodemon --exec babel-node src/index.js

If that doesn't work make sure you have the proper DEV dependencies.

@babel/core
@babel/node
@babel/cli
@babel/preset-env

configure .babelrc to have the following

{ 
  "presets" : ["@babel/preset-env"]
}
Related