【问题标题】:Can't get VSCode debbuging to work with my NodeJs app无法让 VSCode 调试与我的 NodeJs 应用程序一起使用
【发布时间】:2019-04-13 20:25:07
【问题描述】:

我正在尝试在 Visual Studio Code 上调试我的应用程序。我的package.json 上有以下配置:

"scripts": {
    "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
    "start": "npm run build && node --inspect=12345 dist/app.js"
}

我在我的 Node 应用程序上使用 ES6,这就是为什么我的 build 配置有点混乱。

当我运行npm start 时一切正常,我可以使用我的应用程序。

现在尝试调试它,我设置了以下launch 配置:

"configurations": [
    {
        "type": "node",
        "name": "Attach to Remote",
        "request": "attach",
        "port": 12345
    },
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}\\dist\\app.js"
    }
]

它们都“工作”:VS Code 切换到“调试模式”,但我无法命中任何断点。它们都变灰了:

我已尝试使用this 答案进行修复,但无法使其正常工作...

有什么帮助吗?

提前致谢!

【问题讨论】:

    标签: node.js debugging visual-studio-code vscode-debugger


    【解决方案1】:

    我正在使用 VS Code v 1.28.2,并且能够以两种方式进行调试。

    1) 使用内置调试器(菜单 -> 调试 -> 开始调试)

    2) 使用node inspect index.js 启动应用程序。在这种情况下,您必须使用 debugger; 关键字在代码中声明断点。然后,当处于调试模式并在断点处停止时,您继续执行在命令行中键入 cont

    希望对你有帮助

    【讨论】:

    • 感谢您的回答,gkont。这确实有效,但我希望使用断点而不是调试器。我找到了解决方案!谢谢!
    【解决方案2】:

    我发现我的babel-cli 命令中缺少--source-maps... -.- 添加后,VSCode 能够找到断点。 所以基本上解决方案是:

    --source-maps 添加到我的构建命令中:

    "scripts": {
        "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files --source-maps",
        "start": "npm run build && node --inspect=12345 dist/app.js"
     }
    

    我配置了一个launch如下:

    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}\\dist\\app.js",
            "preLaunchTask": "npm: build"
        }
    ]
    

    希望它对某人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-06
      • 2020-03-27
      • 2017-03-05
      • 1970-01-01
      相关资源
      最近更新 更多