fyardlest
fyardlest

Reputation: 298

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

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!

Upvotes: 4

Views: 8188

Answers (2)

Boris Torrejon
Boris Torrejon

Reputation: 144

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

Upvotes: 10

Dallas Baker
Dallas Baker

Reputation: 376

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"]
}

Upvotes: 2

Related Questions