Mic*_*rra 36 node.js nodemon visual-studio-code
我已经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它与节点完美地运行
Adr*_*n T 44
首先,将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属性和指向正常入口点脚本的属性.
Mat*_*hew 31
我无法得到@AdrianT的答案,附带调试器.看起来有一种更新的内置支持方式来执行此操作:
它会在你的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.
Yev*_*eni 15
在Visual Studio代码中创建启动配置:
{
    "name": "Attach",
    "type": "node",
    "request": "attach",
    "port": 5858,
    "restart": true
}
从命令行运行nodemon: nodemon --debug server.js
现在从VC和vuala'附加'.
附加绝对是一个简单的选择。为了确保您的代码中断,请确保您使用--inspect-brk(节点 8+)运行 nodemon ,例如:
nodemon --inspect-brk src/app.js
启动 nodemon 后,将记录为调试连接打开的端口:
Debugger listening on ws://127.0.0.1:9229/someUUID
您可以使用该端口来构建您的启动配置,这非常简单:
{
  "type": "node",
  "request": "attach",
  "name": "Attach",
  "port": 9229,
  "restart": true
},
不,目前还不能。但我设法使用nodemon 让它在某种程度上发挥作用。我从 Grunt 开始。但等效的命令行应该做同样的事情。
\n\n编辑:经过一晚上的测试,我可以说下面的方法仍然有点不稳定:S,附加间歇性失败,有时断点被忽略。
\n\nEDIT2[\'--debug-brk=5860\'] :您还可以使用for在 Gruntfile 中指定非默认调试端口nodeArgs。我还被建议使用--debug-brk而不是--debug. 也许这会消除目前的不稳定。如果有帮助的话我会回来并在这里提及(我目前已经切换了项目)。
如果这可能对 Windows 10 上当前 VS Code 版本(例如 v0.10.6)中使用以下设置的任何人有帮助。但它可能也适用于 Mac(我可能稍后会检查)。但请注意,有时我必须在调试器选择文件之前通过更改+保存文件来触发重建。
\n\n/.vscode/launch.json
{\n"configurations": [{\n    "name": "Launch",\n    "outDir": null\n\n},{\n    "name": "Attach",\n    "type": "node",\n    "request": "attach",\n    "port": 5858\n}]\n}
\n\n/Gruntfile.js
nodemon : {\n    dev : {\n    script : \'launcher.js\'\n    },\n    options : {\n        ignore : [\'node_modules/**\', \'Gruntfile.js\'],\n               nodeArgs: [\'--debug\'],\n        env : { PORT : \'4123\'\n        }\n    }\n}\n我猜调试端口 5858 是默认端口,因为此处未指定它(请注意上面的 \xc3\xads launch.json。)
| 归档时间: | 
 | 
| 查看次数: | 20005 次 | 
| 最近记录: |