node.js - 无法让 VSCode 调试与我的 NodeJs 应用程序一起使用
问题描述
我正在尝试在 Visual Studio Code 上调试我的应用程序。我有以下配置package.json
:
"scripts": {
"build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
"start": "npm run build && node --inspect=12345 dist/app.js"
}
我在我的 Node 应用程序上使用 ES6,这就是我的build
配置有点混乱的原因。
当我运行npm start
一切正常时,我可以使用我的应用程序。
现在尝试调试它,我设置了以下launch
配置:
"configurations": [
{
"type": "node",
"name": "Attach to Remote",
"request": "attach",
"port": 12345
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\dist\\app.js"
}
]
他们俩都“工作”:VS Code切换到“调试模式”,但我不能打任何断点。它们都变灰:
我已尝试使用此答案进行修复,但无法使其正常工作...
有什么帮助吗?
提前致谢!
解决方案
我发现我只是错过了--source-maps
命令中的babel-cli
... -.- 添加它之后,VSCode 能够找到断点。所以基本上解决方案是:
添加--source-maps
到我的构建命令:
"scripts": {
"build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files --source-maps",
"start": "npm run build && node --inspect=12345 dist/app.js"
}
我配置launch
如下:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\dist\\app.js",
"preLaunchTask": "npm: build"
}
]
希望它可以帮助某人!
推荐阅读
- javascript - JavaScript节点中的承诺值未更新变量值
- garbage-collection - 强制对 WeakReference 的目标进行垃圾回收
- angular - 单击时的 Angular Material 选项卡波纹效果不适用于拉伸后的完整选项卡
- flutter - 无法使用颤振和 Firebase 注销但我可以登录
- sql - 将 Hibernates @SqlDelete 与 JPA 的 @PreRemove 挂钩结合使用
- angularjs - 在条目中使用 Webpack 插件输出。AngularTemplateCacheWebpackPlugin
- c - 设置目标节标题后 elf_update() 中的问题
- pytorch - Pytorch DataLoader 返回可迭代,如何以及何时转换为张量以进行模型训练
- c++ - OpenCV DNN 不使用 Deeplabv3.onnx 模型产生预期结果
- kubernetes - 某些 Prometheus 警报最终显示为“未分组”