node.js VS Code 未验证断点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50804332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VS Code Unverified Breakpoints
提问by beachCode
I'm trying to debug a Node/Express TypeScript app in VS Code (v. 1.24.0) and all my breakpoints are greyed out during debugging.
我正在尝试在 VS Code (v. 1.24.0) 中调试 Node/Express TypeScript 应用程序,并且在调试期间我的所有断点都显示为灰色。
The error is "Unverified Breakpoint, Breakpoints set but not yet bound." I've searched but can't figure out what's wrong with my config. There is no error in the console, the debugger attaches successfully when I choose the process, but the breakpoints don't work.
错误是“未验证的断点,断点已设置但尚未绑定。” 我已经搜索过,但无法弄清楚我的配置有什么问题。控制台没有错误,我选择进程时调试器附加成功,但是断点不起作用。
How do I debug this?
我该如何调试?
basic folder structure:
基本文件夹结构:
/.vscode
/src/server.ts
/dist/server.js
launch.json
tsconfig.json
launch.json
启动文件
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"protocol": "inspector",
"address": "localhost",
"port": 8080,
"restart": true,
"preLaunchTask": "npm: build",
"sourceMaps": true,
"outFiles" : [ "${workspaceFolder}/dist/**/*.js" ]
},
tsconfig.json
配置文件
{
"compilerOptions": {
"alwaysStrict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es6",
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"typeRoots": [ "node_modules/@types" ]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
tasks.json
任务文件
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"group": {
"kind": "build",
"isDefault": true
}
} ]
采纳答案by beachCode
For anyone who runs into this error, I was able to find a solution. The issue was the way I was launching the Node process, not the mapping of the source maps (which produces a different error).
对于遇到此错误的任何人,我都能找到解决方案。问题是我启动 Node 进程的方式,而不是源映射的映射(这会产生不同的错误)。
To attach to the process, I launched it from the VS Code terminal like this:
为了附加到该进程,我从 VS Code 终端启动它,如下所示:
node --inspect dist/server.js
launch.json:
启动.json:
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"protocol": "inspector",
"address": "localhost",
"port": 8080,
"restart": true,
"preLaunchTask": "npm: build",
"sourceMaps": true,
"outFiles" : [ "${workspaceRoot}/dist/**/*.js" ]
},
回答by Dr.YSG
I was finding all the breakpoints I tried to set in one file got this problem, but non of the rest.
我发现我试图在一个文件中设置的所有断点都遇到了这个问题,但其余的都没有。
I was naming the file dispatcher.js with a lower case, but pulling it into node with:
我用小写命名文件 dispatcher.js ,但将其拉入节点:
const { Dispatcher } = require('./Dispatcher')
and the contents was a javascript class being exported as:
内容是一个 javascript 类,导出为:
module.exports = { Dispatcher }
回答by omnivorosaur
I encountered this problem using vscode 1.25
我在使用 vscode 1.25 时遇到了这个问题
Looks like it's triggered when a breakpoint-containing source (.ts) is changed while Debug session is running. The breakpoints could be re-enabled by re-saving the source, or by re-togglig the breakpoint.
看起来它是在调试会话运行时更改包含断点的源 (.ts) 时触发的。可以通过重新保存源代码或重新切换断点来重新启用断点。
However if the source was changed, then debugging has to be restarted to be in-sync with the source.
但是,如果源已更改,则必须重新启动调试以与源同步。
This issue seems to spill into the Edit mode too, the breakpoints would remain "Unverified" even after leaving the Debug mode. Again, re-saving the source appears to re-enable the breakpoints in this case.
这个问题似乎也蔓延到编辑模式,即使离开调试模式,断点也会保持“未验证”。同样,在这种情况下,重新保存源似乎可以重新启用断点。
回答by Leigh Mathieson
I was running into an identical issue; if an error was present, the debugger would report on the error, but if no error it would not stop on breakpoints. The change that resolved for me was to specify the exact filename that would be served rather than just localhost. For example on NodeJS, Express just specifying localhost:3000would not stop on my breakpoints, but specifying localhost:3000/index.htmlworked as expected
我遇到了同样的问题;如果存在错误,调试器将报告错误,但如果没有错误,它不会在断点处停止。为我解决的更改是指定将提供的确切文件名,而不仅仅是本地主机。例如在 NodeJS 上,仅指定 Expresslocalhost:3000不会在我的断点处停止,但指定localhost:3000/index.html按预期工作
Full config which stops on breakpoints as expected (to date):
完整配置按预期停止在断点处(迄今为止):
My folder open in VSCode: learningPixiwith full folder location (Ubuntu Linux): /home/leigh/node/pixi-tut/learningPixi
我的文件夹在 VSCode 中打开:learningPixi带有完整文件夹位置(Ubuntu Linux):/home/leigh/node/pixi-tut/learningPixi
My folder structure is:
我的文件夹结构是:
/home/leigh/node/pixi-tut/learningPixi/.vscode/launch.json
/home/leigh/node/pixi-tut/learningPixi/public/index.html
/home/leigh/node/pixi-tut/learningPixi/server.js
/home/leigh/node/pixi-tut/learningPixi/.vscode/launch.json
/home/leigh/node/pixi-tut/learningPixi/public/index.html
/home/leigh/node/pixi-tut/learningPixi/server.js
Contents of my launch.json file:
我的 launch.json 文件的内容:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000/index.html",
"webRoot": "${workspaceFolder}/public",
"skipFiles": ["pixi.min.js"]
}
]
}
"skipFiles" was also very useful otherwise debugger steps into every function call
“skipFiles”也非常有用,否则调试器会进入每个函数调用
My (very basic) express server config just for debugging JavaScript in static files was:
我的(非常基本的)快速服务器配置仅用于在静态文件中调试 JavaScript:
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, '/public')));
app.listen(3000, () => console.log('App started on port 3000'));
And as per folder structure above ensure index.html is located in /public folder
根据上面的文件夹结构确保 index.html 位于 /public 文件夹中
If debugging JavaScript from within an HTML file, you may also need to go to settings within VSCode and enable: Allow Breakpoints Everywhere
如果从 HTML 文件中调试 JavaScript,您可能还需要转到 VSCode 中的设置并启用:Allow Breakpoints Everywhere
回答by Fillip Peyton
For future readers: I ran into this issue because I had ran a prod build of my app before trying to debug. The prod build removes the sourcemaps that VS Code needs to debug successfully, so I ran a dev build of my app and then debug, and everything worked as expected.
对于未来的读者:我遇到了这个问题,因为我在尝试调试之前运行了我的应用程序的生产版本。prod 构建删除了 VS Code 需要成功调试的源映射,所以我运行了我的应用程序的开发构建然后调试,一切都按预期工作。
回答by MattG
I got this issue today, I tried re-building, and re-running debugger. I shut down all VS Code instances and restarted, working now.
我今天遇到了这个问题,我尝试重新构建并重新运行调试器。我关闭了所有 VS Code 实例并重新启动,现在可以工作了。

