angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

SourceMap mapping webpack to wrong file location in VSCode Debug

Open pderks opened this issue 10 years ago • 44 comments

OS: Windows 10 angular-cli: 1.0.0-beta.16 node: 6.7.0

When creating a new project using the angular-cli and attempting to debug, none of the breakpoints I am setting are being hit. After looking into the log file for the debugger I have found that webpack is mapping to the wrong source location. I have listed repro steps along with the location of a log file, my launch configurations and an example of what I am seeing when I say that webpack is mapping to the wrong location. I was hoping someone had some insight into why this is happening.

Repro steps:

  1. Download Debugger for Chrome in VS Code
  2. Create new project using angular-cli
  3. Set Launch.json configurations to launch in chrome with diagnosticLogging set to true
  4. Set breakpoints in typescript files and Launch the app
  5. Log file can be found at C:\Users{{your username}}.vscode\extensions\msjsdiag.debugger-for-chrome-0.5.2\vscode-chrome-debug.txt

Example from the log (entire log file attached): vscode-chrome-debug.txt

SourceMap: mapping webpack:///C:/Users/pderks/Desktop/test-app/src/app/app.component.ts => c:\Users\pderks\Desktop\test-app\C:\Users\pderks\Desktop\test-app\src\app\app.component.ts

**Notice that the path c:\Users\pderks\Desktop\test-app is appearing twice.

Launch configurations: { "version": "0.2.0", "configurations": [ { "name": "Launch Chrome against localhost, with sourcemaps", "type": "chrome", "request": "launch", "url": "http://localhost:4200", "diagnosticLogging": true, "sourceMaps": true, "webRoot": "${workspaceRoot}" } ] }

pderks avatar Sep 30 '16 23:09 pderks

@andresbm05 's solution fixed it for me as well!

jakehockey10 avatar Apr 23 '18 16:04 jakehockey10

In my case, the configuration for launch was set right but my code still wasn't hitting the breakpoints. The intent was to add breakpoints on my VS to debug locally with my local angular project.

Simply ran 'ng build' before hitting 'npm run localhmr' on my angular project to get into debug mode. Hope this helps others in a similar situation.

zkhancps avatar Apr 05 '19 16:04 zkhancps

To make breakpoints work in @angular/cli library projects, I had to configure the launch like this:

BTW, I use scoped packages: @SCOPED_PACKAGE_NAME/PROJECT_NAME

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///ng://@SCOPED_PACKAGE_NAME/PROJECT_NAME/lib/*": "${workspaceRoot}/projects/PROJECT_NAME/src/lib/*",
        "webpack:///*": "${workspaceRoot}/*"
      }
    }
  ]
}

nlaplante avatar May 07 '19 16:05 nlaplante

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.