Debugging VS代码“;断点被忽略,因为未找到生成的代码”;使用vscode chrome调试JS代码时出错
在Windows 10上,我制作了非常简单的node Express应用程序:Debugging VS代码“;断点被忽略,因为未找到生成的代码”;使用vscode chrome调试JS代码时出错,debugging,visual-studio-code,Debugging,Visual Studio Code,在Windows 10上,我制作了非常简单的node Express应用程序: investigate-debugger +--.vscode +-- launch.json +-- app.js +-- index.html +-- program.js 服务器以app.js代码启动: //////////////////app.js var express = require('express'); var app = express(); app.use(express.stat
investigate-debugger
+--.vscode
+-- launch.json
+-- app.js
+-- index.html
+-- program.js
服务器以app.js代码启动:
//////////////////app.js
var express = require('express');
var app = express();
app.use(express.static('.'));
app.listen(8080, function () {
console.log('Example app listening on port 8080!');
});
index.html只加载program.js文件:
//////////////////index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script src="program.js"></script>
</head>
<body>
</body>
</html>
//////////////////program.js
var x = 5;
var y = 4; // here is “Breakpoint ignored because generated code not found”
console.log(5 + 4);
当我运行调试器时,我在调试器控制台中看到输出9,我看到浏览器以正确的路径打开,但断点在program.js中不起作用,第2行:
我哪里做错了?尝试将
'/*'
添加到您的站点“url”中
这告诉VS代码它应该跟踪调试中的所有文件
这为我解决了问题 要在所有文件中启用断点,您需要修改settings.json。 (文件->首选项->设置) 我还注意到,在使用chrome调试器时,需要指定实际的html文件作为URL的一部分。例如,当您调试时,chrome可能会以localhost:8080的形式打开,这将不起作用。相反,您需要指定实际页面,例如localhost:8080/index.html 希望这对某人有所帮助。请参阅。你需要调整你的源地图 默认配置可能不适合您的情况。调整后,在调试控制台中运行.scripts命令以查看输出 确保以下两点 1) .js文件被映射到正确的绝对路径
2) 如果有多个相同的文件,请让正确的文件映射到正确的路径,而让其他文件映射到错误的路径。最有可能的情况是,您应该启用sourcemaps,因为调试需要它们。另外,如果您使用webpack,您可能需要调整webpack的设置,以生成VSCode可以找到并用于调试的源映射。没有webpack或其他绑定器。不管sourceMapsI如何,事情对我都不起作用。我已经为自己解决了这个问题,并为此撰写了一篇博文。也许有人会觉得这很有帮助:@AlexanderNechay您提供的博客链接中没有任何内容,您是想包含其他链接吗?@Azurespot,很抱歉,我的提供商丢失了我的网站数据。我已经重新发表了关于媒体的文章:这对我不起作用。它说*不是一个网站。
{
"version": "0.2.0",
"configurations": [
{
"name": "Chrome, launch",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080",
"webRoot": "${workspaceRoot}",
"diagnosticLogging": false,
"sourceMaps": false,
"userDataDir": "${workspaceRoot}/.vscode/chrome"
}
]
}
"url": "http://localhost:8080/*",
// Place your settings in this file to overwrite default and user settings.
{
"debug.allowBreakpointsEverywhere": true
}