Angular CLI 1.7.0 and Visual Studio Code - can't set breakpoints

前提是你 提交于 2019-11-27 01:48:13

For those coming across this the fix is to modify your launch.json sourceMapPathOverrides as follows:

"sourceMapPathOverrides": { 
    "webpack:/*": "${webRoot}/*" 
}

This fixed it for me with the latest @angular/cli (version 1.7.3).

Answer was found here.

Angular CLI 7.2.2:

Webstorm/Intellij - breakpoints never hit, VSCode - breakpoints unverified/never hit, Chrome debugger - breakpoints hit perfectly.

Solution: in angular.json set evalSourceMap to "false".

This triggers the Webpack that Angular CLI uses under the hood to generate source maps to original source code ("source-map") instead of generated code ("eval"). https://webpack.js.org/configuration/devtool

See under node_modules@angular-devkit\build-angular\src\angular-cli-files\models\webpack-configs\browser.js

You can of course hack the browser.js file to set some other value for devtool.

Yes, same thing here.

Sometimes I can reach the breakpoint I want with some difficulty (the issue seems to be with the sourcemap, but the debugger is still functional).

I tried fiddling with some settings in the VS-Code debugger launch configuration ("sourceMaps" and "trace"), but to no avail.

Eventually I rolled back @angular/cli to 1.6.8 and it works fine again.

Edit: Forgot to mention, in case it helps someone searching for this issue - when starting debugging, the breakpoints disappear from the source file and its tab is marked with "read-only inlined content from source map".

Also, @angular/cli 1.7.1 does not resolve this.

Same here, rolled back to 1.6.8 (and angular 5.1.1) to get my breakpoints working again.

Setting sourceMapPathOverrides was not sufficient.

In my case the index.html file is located in "/src", and Angular components in "/src/app". I use @angular/cli 1.7.4, vscode 1.22.2 and chrome debugger 4.3.0.

I had to set three parameters in the launch.json.

"sourceMapPathOverrides": { 
    "webpack:/*": "${webRoot}/*"
},
"webRoot": "${workspaceFolder}",
"sourceMaps": true,

sourceMaps is optional but make sure it is not set to false.

It must be set for each configuration of the launch.json config file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Chrome DEBUG 172.22.44.49",
            ...

In the chrome debugger sourcemaps documention, It is said to set webRoot to the directory that files are served from. But to solve this issue I had to set it to the workspace root directory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!