【发布时间】:2017-08-16 14:58:28
【问题描述】:
在 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.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);
我已经通过以下方式配置了launch.js:
{
"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"
}
]
}
当我运行调试器时,我在调试器控制台中看到输出 9,我看到浏览器以正确的路径打开,但断点在 program.js 第 2 行中不起作用:
我在这里做错了什么?
【问题讨论】:
-
很可能您应该启用源映射,因为它们是调试所需的。此外,如果您使用 webpack,您可能需要调整 webpack 的设置以生成 VSCode 可以找到并用于调试的源映射。
-
没有 webpack 或其他 bandler。无论sourceMaps如何,事情都对我不起作用
-
我自己解决了这个问题,并整理了一篇关于这个的博客文章。也许有人会觉得它有帮助:nechai.net/2017/03/22/…
-
@AlexanderNechay 您提供的博客链接中没有任何内容,您的意思是要包含其他链接吗?
-
@Azurespot,很抱歉,我的提供商丢失了我网站的数据。我已经在medium上重新发布了这篇文章:medium.com/@nechais/…
标签: debugging visual-studio-code