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

孤人 提交于 2021-02-11 13:18:23

问题


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

> dev_forum@1.0.0 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..

(*this is my first question ;) )


回答1:


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",


来源:https://stackoverflow.com/questions/65827453/nodemon-babel-node-not-recognized-as-internal-or-external-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!