【问题标题】:Trying to run "npm run start" in VS Code's Debug on Windows 10尝试在 Windows 10 上的 VS Code 调试中运行“npm run start”
【发布时间】:2019-05-30 00:36:55
【问题描述】:

通常,我运行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.

如果我在program 下使用node 进行调试会话,这一切都很好。

其他:

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

我尝试将 program 更改为该路径,但没有成功。

【问题讨论】:

  • 我根据which 命令假设您已将 VSCode 配置为使用 WSL 作为集成终端?
  • 不,使用 git-bash
  • 等等,你在 VSCode 中使用 git-bash?
  • 我在 hyper 中运行 which 以找出 npm 的位置,因为它将由 cmd/powershell 通过 vs code 执行。我只是好奇它在 Windows 系统上的位置。它不是由 vs code 运行的。
  • 这个错误出现在哪里?您能否发布错误出现在 VSCode 窗口上的屏幕截图?

标签: node.js npm visual-studio-code


【解决方案1】:

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

program - executable or file to run when launching the debugger

【讨论】:

  • 我可以从 powershell 运行 npm 就好了。
  • npm run start 只是在 package.json 中启动 start 脚本。由于您想在visual-studio代码中运行它,您必须遵循launch.json的标准,这需要您将可执行文件放在字段program
  • 您可以在此处查看文档以获取更多信息:go.microsoft.com/fwlink/?linkid=830387 希望对您有所帮助。
  • 我的 npm run start 只是执行“electron”。这也失败了。
猜你喜欢
  • 1970-01-01
  • 2020-07-12
  • 2019-02-10
  • 2020-12-21
  • 1970-01-01
  • 1970-01-01
  • 2021-01-08
  • 2020-12-18
相关资源
最近更新 更多