【问题标题】:Run "npm start" in debug configuration for NodeJS app in VS Code在 VS Code 的 NodeJS 应用程序的调试配置中运行“npm start”
【发布时间】:2017-12-18 01:53:59
【问题描述】:

我目前正在尝试通过 Visual Studio 代码调试我的 NodeJS 应用程序。当我通过 PowerShell 运行程序时,我使用“npm start”运行它。尝试在 Visual Studio Code 中调试应用程序时,我在 NodeJS 内部文件中遇到错误。这是我的配置文件的样子(这是提供的默认配置文件):

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}\\server.js"
        }
    ]
}

尝试将“程序”更改为“npm start”不起作用。

【问题讨论】:

    标签: node.js visual-studio-code


    【解决方案1】:

    您可以使用启动配置运行 npm 脚本,但您的 npm 脚本需要在调试模式下启动节点。示例:

    在 package.json 中:

    "scripts": {
      "start": "node --nolazy --inspect-brk=9229 server.js
    }
    

    launch.json:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "runtimeExecutable": "npm",
                "runtimeArgs": [ "start" ],
                "port": 9229
            }
        ]
    }
    

    或者,更改您的启动配置以执行 npm start 正在执行的操作。

    在启动配置中使用“npm”的文档:https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      相关资源
      最近更新 更多