位置:首页 > 后端 > node

express使用nodemon实现热加载报错

dearweb 发布:2021-08-21 10:48:20阅读:

express使用nodemon实现热加载报错,UnhandledPromiseRejectionWarning: Error: Command failed: wmic process where (ParentProcessId=21240) get ProcessId。

查阅了不少资料,最终解决了这个棘手的问题,首先看下错误代码

安装完了之后保存就报错

(node:15468) UnhandledPromiseRejectionWarning: Error: Command failed: wmic process where (ParentProcessId=21240) get ProcessId 2> nul
    at checkExecSyncError (child_process.js:640:11)
    at execSync (child_process.js:676:15)
    at kill (E:\node_study\express-app\node_modules\nodemon\lib\monitor\run.js:345:26)
    at Function.run.kill (E:\node_study\express-app\node_modules\nodemon\lib\monitor\run.js:437:7)
    at Bus.<anonymous> (E:\node_study\express-app\node_modules\nodemon\lib\monitor\run.js:507:7)
    at Bus.emit (events.js:388:22)
    at restartBus (E:\node_study\express-app\node_modules\nodemon\lib\monitor\watch.js:228:7)
    at FSWatcher.filterAndRestart (E:\node_study\express-app\node_modules\nodemon\lib\monitor\watch.js:212:16)
    at FSWatcher.emit (events.js:376:20)
    at FSWatcher.emitWithAll (E:\node_study\express-app\node_modules\chokidar\index.js:540:8)
(node:15468) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

小编的安装步骤

首先执行安装命令

npm install nodemon --save

修改package配置文件

"scripts": {
    "start": "node ./bin/www",
    "devstart": "nodemon ./bin/www" //增加一行
  },

完成之后执行命令跑服务

npm run devstart

执行完之后再次修改文件报错的时候就出现了上面说看到的错误提示,服务也没有更新,然后小编就不停的百度和谷歌,最终找到了解决方案,发现是安装的 nodemon 版本不对,然后重新卸载安装了一遍

//卸载
npm uninstall nodemon

//安装
npm install nodemon@2.0.7 --save-dev

// 执行
npm run devstart

结果是服务顺利跑起来了,哈哈,小编是不是很会找答案,加油小伙伴们,如果你也是报和小编同样的错误,不妨试试修改下安装版本。

24人点赞 返回栏目 提问 分享一波

小礼物走一波,支持作者

还没有人赞赏,支持一波吧

留言(问题紧急可添加微信 xxl18963067593) 评论仅代表网友个人 留言列表

暂无留言,快来抢沙发吧!

本刊热文
网友在读
手机扫码查看 手机扫码查看