我已经nodemon
在我的系统中安装了一个全局包.它nodemon
在cmd中执行时有效.
但是当我在这个launch.json
文件中使用vscode时,vscode会抛出此异常:
请求启动:运行时可执行文件XXX\XXX\XXX\XXX \nodemon不存在
launch.json是:
{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "node", "request": "launch", "program": "app.js", "stopOnEntry": false, "args": [], "cwd": ".", "runtimeExecutable": nodemon, "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development" }, "externalConsole": false, "preLaunchTask": "", "sourceMaps": false, "outDir": null }, { "name": "Attach", "type": "node", "request": "attach", "port": 5858 } ] }
当我擦除nodemin时,runtimeExecutable
它与节点完美地运行
首先,将nodemon安装为dev依赖项:
npm install --save-dev nodemon
对于较新版本的VS Code,请按.vscode/launch.json
如下方式设置文件:
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js", "program": "${workspaceFolder}/app.js", "restart": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" }] }
最重要的部分是runtimeExecutable
指向nodemon脚本的program
属性和指向入口点脚本的属性.
如果您使用较旧的VS代码(您不应该使用),请尝试以下启动配置:
{ "version": "0.2.0", "configurations": [ { "name": "Launch with nodemon", "type": "node", "request": "launch", "program": "${workspaceRoot}/node_modules/nodemon/bin/nodemon.js", "args": ["${workspaceRoot}/app.js"], "runtimeArgs": ["--nolazy"] } ] }
最重要的部分是program
指向nodemon脚本的args
属性和指向正常入口点脚本的属性.
我无法得到@AdrianT的答案,附带调试器.看起来有一种更新的内置支持方式来执行此操作:
打开Launch Configuration下拉列表并选择"Add configuration ..."
选择"Node.js:Nodemon Setup"
它会在你的launch.json中添加这样的东西:
{ "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "nodemon", "program": "${workspaceRoot}/app.js", "restart": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" }
确保您的"程序"设置是正确的入口点脚本.
您需要全局安装nodemon才能使其正常工作(npm install -g nodemon)(根据文档)
您的应用程序现在运行,您可以设置将被命中的断点,控制台将记录到集成终端窗口.
请注意,终止调试会话只会终止要调试的程序,而不是nodemon本身.要终止nodemon,请在集成终端中按Control-C.
在Visual Studio代码中创建启动配置:
{ "name": "Attach", "type": "node", "request": "attach", "port": 5858, "restart": true }
从命令行运行nodemon: nodemon --debug server.js
现在从VC和vuala'附加'.