我目前正在尝试通过 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"
}
]
}
尝试将“program”更改为“npm start”无效。
最佳答案
您可以使用启动配置运行 npm 脚本,但您的 npm 脚本需要以 Debug模式启动 Node 。示例:
在 package.json 中:
"scripts": {
"start": "node --nolazy --inspect-brk=9229 server.js
}
启动.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
关于node.js - 在 VS Code 的 NodeJS 应用程序的调试配置中运行 "npm start",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47861187/