VS代码无法正确设置断点 [英] VS Code Can't Set Breakpoints Properly
问题描述
我正在尝试调试一个很小的项目,但无法使Debugger for Chrome扩展程序完全发挥作用.当我放置一个断点时,它会移到我要调试的功能之外.
I'm attempting to debug a tiny project but I'm unable to get the Debugger for Chrome extension to fully work. When I place a breakpoint it gets moved outside of the function I want to debug.
我正在使用webpack + babel.我的项目托管在.Net平台(特别是DNN)上.
I'm using webpack + babel. My project is being hosted on a .Net platform (specifically DNN).
package.json:
package.json:
{
"name": "disable-registration",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "npm-watch"
},
"babel": {
"presets": [
"env"
]
},
"watch": {
"build": "src/*.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.3.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-preset-env": "^1.6.1",
"npm-watch": "^0.3.0",
"webpack": "^4.0.1",
"webpack-cli": "^2.0.9"
}
}
launch.json:
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "attach",
"name": "Attach to mickys.dnndev.me",
"port": 9222,
"url": "http://www.mickys.dnndev.me/",
"webRoot": "${workspaceFolder}",
"sourceMaps": true,
"skipFiles": ["node_modules"]
}
]
}
确实会设置断点,但是它会完全跳过我的代码.我可以在Chrome开发工具中成功设置一个断点,但是这打破了利用ES6语法的目的.几天来一直在尝试解决此问题,但没有找到解决方案.
The breakpoints that do get set will hit but it completely skips my code. I can put a breakpoint in the Chrome dev tools successfully but that defeats the purpose of taking advantage of ES6 syntax. Been trying to resolve this for days and haven't found a solution.
更新:尝试将我的const值更改为let或var无法解决问题:
Update: tried changing my const value to let or var doesn't resolve the issue:
我现在可以看到它正在尝试调试正确的文件,但是行号不同步.这是我在chrome开发工具中看到的:
I can now see that it is trying to debug the correct file however the line numbers are out of sync. This is what I see in the chrome dev tools:
推荐答案
感谢此帖子我能够解决我的问题.
Thanks to this post I was able to resolve my issue.
我用以下几行创建了一个.babelrc文件:
I created a .babelrc file with these lines:
{
"presets": ["env"],
"sourceMaps": "inline",
"retainLines": true
}
现在达到了预期的断点.是的!
Now breakpoints hit as expected. Yay!
但是,我相信我有一个单独的问题:调试时我没有任何智能感知.我可以查看变量的值,但看不到其他任何文本(函数,关键字等).
However, I believe I have a separate issue: I don't get any intellisense while debugging. I can view the value of a variable but I don't see text on anything else (functions, keywords, etc).
希望这对某人有帮助:)
Hope this helps someone :)
这篇关于VS代码无法正确设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!