使用WSL在VSCode中使用nodemon + babel-node进行调试

问题描述 投票:0回答:1

我正在尝试使用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

谢谢

node.js babel vscode-debugger
1个回答
0
投票

我遇到了同样的问题...在尝试了很多启动配置组合之后,我找到了正确的设置。

{
  "type": "node",
  "request": "attach",
  "name": "Attach Program",
  "protocol": "inspector",
  "restart": true,
  "skipFiles": [
    "<node_internals>/**"
  ],
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "/",
}

Ps:我使用--inspect参数(允许调试器附加节点)使用nodemon启动节点脚本。

© www.soinside.com 2019 - 2024. All rights reserved.