代码之家  ›  专栏  ›  技术社区  ›  João Menighin

无法使VSCode Debbug与我的NodeJs应用程序一起工作

  •  0
  • João Menighin  · 技术社区  · 6 年前

    我正在尝试用Visual Studio代码调试我的应用程序。我的电脑上有以下配置 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"
    }
    

    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代码切换到“调试模式”,但我无法命中任何断点。它们都变灰了:

    enter image description here

    我已尝试使用 this 回答,但无法让它工作。。。

    2 回复  |  直到 6 年前
        1
  •  0
  •   gkont    6 年前

    我使用的是VS代码V1.28.2,并且我能够以两种方式进行调试。

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

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

    希望能有帮助

        2
  •  0
  •   João Menighin    6 年前

    我发现我只是错过了比赛 --source-maps babel-cli 命令…-- 添加它之后,VSCode能够找到断点。 因此,基本上解决方案是:

    添加 --源地图 要执行我的生成命令,请执行以下操作:

    "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"
        }
    ]
    

    希望它能帮助别人!