我目前正在尝试通过visual studio代码调试我的NodeJS应用程序。当我通过PowerShell运行程序时,我使用“npm start”运行它。尝试在Visual Studio代码中调试应用程序时,我在NodeJS内部文件中出现错误。这是我的配置文件的样子(它是默认的配置文件):
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\server.js"
}
]
}
尝试将“程序”更改为“npm start”不起作用。
答案 0 :(得分:5)
You can run npm scripts with a launch configuration, but your npm script needs to start node in debug mode. Example:
In 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
}
]
}
or, change your launch config to do exactly whatver npm start
is doing.
Docs for using 'npm' in launch config: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools