首页 > 解决方案 > 停止调试器后如何让vscode同时停止nodemon和npm?

问题描述

我正在运行以下 launch.json 配置和 package.json 脚本,它运行良好,我能够运行应用程序并对其进行调试。但是,当我在 vscode 调试器中点击“停止”按钮时,nodemon 停止了,但 npm 进程(以及整个应用程序)继续运行。如果我修改文件并保存它,那么 nodemon 会再次恢复(如预期的那样)。真正停止应用程序的唯一方法是在终端中按 ctrl+c。单击调试器停止按钮后,有没有办法停止这两个进程?

package.json 脚本

"scripts": {
 "start": "node app",
 "debug": "nodemon --experimental-modules --inspect ./bin/www.mjs"
}

启动.json 配置

{
 "type": "node",
 "request": "launch",
 "name": "Launch via NPM",
 "runtimeExecutable": "npm",
 "runtimeArgs": [
  "run-script",
  "debug"
 ],
 "port": 9229,
 "restart": true,
 "console": "integratedTerminal"        
}

标签: npmvisual-studio-code

解决方案


似乎解决方案是添加--exitcrash标志。它对我有用(至少当我刚开始测试它时)。所以:

"scripts": {
  "start": "node app",
  "debug": "nodemon --experimental-modules --inspect --exitcrash ./bin/www.mjs"
}

或者:

 "runtimeArgs": [
   "run-script",
   "debug",
   "--exitcrash"
 ],

我从这里得到了这个想法: https ://github.com/microsoft/vscode/issues/56756#issuecomment-462585020


推荐阅读