1、错误详情
$ npm run dev > bxapp@1.0.0 dev /Users/xuzhaoning/WeChatProjects/bxapp > cross-env NODE_ENV=development nodemon server/index.js --watch server --exec babel-node [nodemon] 1.19.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching dir(s): server/**/* [nodemon] watching extensions: js,mjs,json [nodemon] starting `babel-node server/index.js` sh: babel-node: command not found [nodemon] failed to start process, "babel-node" exec not found [nodemon] Error at Bus.<anonymous> (/Users/xuzhaoning/WeChatProjects/bxapp/node_modules/nodemon/lib/nodemon.js:156:25) at Bus.emit (events.js:215:7) at ChildProcess.<anonymous> (/Users/xuzhaoning/WeChatProjects/bxapp/node_modules/nodemon/lib/monitor/run.js:167:11) at ChildProcess.emit (events.js:210:5) at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
2、错误原因
修改了package.json文件,在dev命令的后面加上了--exec babel-node
,再运行npm run dev
就出现了上面的错误,因为没有添加babel插件
3、解决方法
(1)在项目下面创建.babelrc文件
$ cd project-name $ touch .babelrc
(2)在.babelrc文件中添加下面代码
{ "presets": ["es2015"] }
(3)打开终端,运行语句安装插件
$ npm install babel-preset-es2015 $ npm install babel-cli -S
这样再次启动npm run dev
就成功了