我正在尝试使用VScode调试我的node + babel项目,但没有成功。我读了很多答案,没有人解决我的问题。launch.json应该看起来如何?
我希望能够将调试器附加到正在运行的进程并启动程序。
Package.json
"build-babel": "npx babel src -d dist",
"start": "node dist/server.js",
"dev-start": "nodemon --inspect-brk --exec babel-node ./src/server.js",
首先尝试从:Can Visual Studio Code be configured to launch with nodemon
launch.json
{
"type": "node",
"request": "launch",
"name": "Nodemon",
"runtimeExecutable": "${workspaceRoot}/node_modules/nodemon/bin/nodemon.js",
"args": [
"${workspaceRoot}/src/server.js"
],
"restart": true,
"protocol": "inspector",
"stopOnEntry": true,
},
{
"type": "node",
"request": "attach",
"name": "Attach to app",
"port": 9229,
"address": "localhost",
"sourceMaps": true,
"smartStep": true,
"restart": true
},
更新
我也尝试过:
{
"type": "node",
"request": "launch",
"name": "nodemon",
"runtimeExecutable": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
"program": "${workspaceFolder}/src/server.js",
"restart": true,
"console": "integratedTerminal",
"port": 9229,
"args": ["--exec", "babel-node", "--babel-preset-es2015"],
"internalConsoleOptions": "neverOpen"
}
当从终端运行服务器进程时运行:已附加,但断点未命中”已设置但尚未绑定”
启动过程结果错误:无法连接到运行时进程-原因:无法连接到目标:连接econnrefused 127.0.0.1:9229
谢谢
我遇到了同样的问题...在尝试了很多启动配置组合之后,我找到了正确的设置。
{
"type": "node",
"request": "attach",
"name": "Attach Program",
"protocol": "inspector",
"restart": true,
"skipFiles": [
"<node_internals>/**"
],
"localRoot": "${workspaceFolder}",
"remoteRoot": "/",
}
Ps:我使用--inspect参数(允许调试器附加节点)使用nodemon启动节点脚本。