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

前端 未结 6 1005
执念已碎
执念已碎 2020-11-29 07:46

I\'m using the Chrome Debugger plugin in Visual Studio Code to debug an Angular application. After upgrading to use angular/cli@1.7.0, we can no longer hit breakpoints in t

相关标签:
6条回答
  • 2020-11-29 08:19

    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.

    0 讨论(0)
  • 2020-11-29 08:20

    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.

    0 讨论(0)
  • 2020-11-29 08:21

    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.

    0 讨论(0)
  • 2020-11-29 08:25

    If you are using a WorkSpace with 1 or more Projects..

    Working for me: launch.json

    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "ng serve",
            "url": "http://localhost:4300",
            "webRoot": "${workspaceFolder}/ProjectName",
            "sourceMapPathOverrides": { 
                "webpack:/*": "${webRoot}/*" 
            }
        }
    ]
    

    1- Start Project ng serve --port 4300

    2- Start Debugging

    0 讨论(0)
  • 2020-11-29 08:30

    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.

    0 讨论(0)
  • 2020-11-29 08:35

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

    0 讨论(0)
提交回复
热议问题