首页 > 解决方案 > 尝试在 Windows 10 上的 VS Code 调试中运行“npm run start”

问题描述

通常,我跑来npm run start运行我的程序。我正在尝试使用 VS Code 调试器在运行程序时对其进行调试。

这是我的 launch.json 文件:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(Windows) Launch electron",
      "type": "cppvsdbg",
      "request": "launch",
      "program": "npm",
      "args": ["run", "start"],
      //"preLaunchTask": "build:win32",
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true
    }
  ]
}

当我使用 VS Code 运行它时,我得到的错误是:launch program '' does not exist.

如果我在调试会话中使用nodeunder ,这一切都很好。program

其他事情:

$ which npm 
/c/Program Files/nodejs/npm

我尝试更改program为确切的路径,但没有成功。

标签: node.jsnpmvisual-studio-code

解决方案


我认为原因在于您的“程序”字段,它应该定位可执行文件。一些常见的值就像"program": "${workspaceFolder}/app.js"

program - executable or file to run when launching the debugger

推荐阅读