SourceMap mapping webpack to wrong file location in VSCode Debug
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:
- Download Debugger for Chrome in VS Code
- Create new project using angular-cli
- Set Launch.json configurations to launch in chrome with diagnosticLogging set to true
- Set breakpoints in typescript files and Launch the app
- 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}" } ] }
Well, it seems to works randomly with beta18 I can't make it work anymore :)
I'll see with cli beta 19-3
@tebeco
have you tried ?
"webpack:///C:*":"C:/*"
and
"webRoot": "${workspaceRoot}"
works for me using last angular-cli
My actual working config:
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
//"diagnosticLogging": true, //enable to debug config problems
"url": "http://localhost:4200",
// the next 2 options is to create a new chrome instance without warnings
"runtimeArgs": [
"--disable-session-crashed-bubble",
"--disable-infobars",
"--disable-application-cache",
"--media-cache-size=1",
"--disk-cache-size=1"
],
"userDataDir": "${workspaceRoot}\\chromeDummyDir",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///C:*":"C:/*"
},
"webRoot": "${workspaceRoot}"
}
I have just used @jmesa-sistel 's example. If I run my app with ng serve and then start my debugger, chrome launches with no issue, but any of my breakpoints don't fire and are greyed out with the warning:
Breakpoint ignored because generated code not found (source map problem?).
@georgeedwards did you try with the second comment of this thread? It worked for me in Linux and Windows
EDIT: "--ssl on" option for "ng serve" seems to break the downloading of the bundle/map files for vscode. Works fine without that.
EDIT2: For attach to work had to change chrome launcher link to include (only open 1 tab): --remote-debugging-port=9222 --user-data-dir=remote-profile
Not working fully for me (source maps not loading, can't trigger breakpoints): angular-cli 1.0.0-beta.22-1 VScode 1.8.0 (Debugger for Chrome v2.4.0) Linux Centos7 Chrome 55.0.2883.87 64bit
See log complaints about map files not loading. ng serve -prod --ssl on --proxy proxy.conf.json (with or without -prod makes no difference)
(same results with: "webRoot": "${workspaceRoot}/src/" "webRoot": "${workspaceRoot}" ) launch.json
{ "version": "0.2.0", "configurations": [ { "name": "Launch Chrome against localhost, with sourcemaps", "type": "chrome", "request": "launch", "url": "https://127.0.0.1:4200/", "sourceMaps": true, "diagnosticLogging": true, "sourceMapPathOverrides": { "webpack:///": "/" }, "webRoot": "${workspaceRoot}/src/app" } }
Log output: SourceMaps.loadSourceMapContents: Downloading sourcemap file from https://127.0.0.1:4200/inline.d41d8cd98f00b204e980.bundle.map SourceMaps.loadSourceMapContents: Could not download sourcemap from https://127.0.0.1:4200/inline.d41d8cd98f00b204e980.bundle.map SourceMaps.loadSourceMapContents: Downloading sourcemap file from https://127.0.0.1:4200/inline.d41d8cd98f00b204e980.bundle.js.map SourceMaps.loadSourceMapContents: Could not download sourcemap from https://127.0.0.1:4200/inline.d41d8cd98f00b204e980.bundle.js.map Paths.scriptParsed: could not resolve https://127.0.0.1:4200/styles.b2328beb0372c051d06d.bundle.js to a file under webRoot: /home/user/project/src/app. It may be external or served directly from the server's memory (and that's OK). SourceMaps.getMapForGeneratedPath: Finding SourceMap for https://127.0.0.1:4200/styles.b2328beb0372c051d06d.bundle.js by URI: styles.b2328beb0372c051d06d.bundle.map and webRoot: /home/user/project/src/app SourceMaps.loadSourceMapContents: Downloading sourcemap file from https://127.0.0.1:4200/styles.b2328beb0372c051d06d.bundle.map SourceMaps.loadSourceMapContents: Could not download sourcemap from https://127.0.0.1:4200/styles.b2328beb0372c051d06d.bundle.map SourceMaps.loadSourceMapContents: Downloading sourcemap file from https://127.0.0.1:4200/styles.b2328beb0372c051d06d.bundle.js.map SourceMaps.loadSourceMapContents: Could not download sourcemap from https://127.0.0.1:4200/styles.b2328beb0372c051d06d.bundle.js.map
@mightypenguin same for me (source maps not loading, can't trigger breakpoints): angular-cli 1.0.0-beta.22 VScode 1.8.0 (Debugger for Chrome v2.4.0) Windows 64 Chrome Version 55.0.2883.87 m 64bit
have tried every permutation of launch.json configuration listed on this thread. No luck...
i'm facing the same issue as @georgeedwards, running ng serve, then attaching works, but cannot add breakpoints. any other workarounds?
angular-cli: 1.0.0-beta.24 VSCode: 1.8.1 vscode-chrome-debug: 2.4.1 node: 6.9.2 os: linux x64 (Fedora 25) (UPDATE: Windows 7 too) angular: 2.4.1 Chrome: 55.0.2883.87 (64-bit)
Both of these VSCode debugger launch configs worked for me:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
}
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"url": "http://localhost:4200",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
}
}
]
}
NOTES:
- the
sourceMapPathOverridesgiven above is one of the three default mappings, so I didn't actually need to specify it. But I wanted to be explicit, so I knew which one worked. - the
diagnosticLoggingline is useful for troubleshooting. - for the attach config, the
urlparameter is important. Without it, the debugger warned it detected multiple chrome targets and would pick the first one, which, in my case was wrong; it corresponded to a browser extension. If you don't have any chrome extensions installed or other tabs open, then you don't need it because the debugger will only detect one target. - UPDATE: Successfully tested above config on Windows 7. Both the Launch and Attach configs worked (can set breakpoints in Typescript code). And deleting the
sourceMapPathOverridesproperty, to fallback to the extension's defaults, worked too.
Unfortunately it doesn't work for me.. VSCode ver: 1.9.1 @angular/cli: 1.0.0-beta.31 node: 6.9.4 OS: Windows 10 Chrome version: 56.0.2924.87 angular: 2.4.7
Launch partially works by attaching but doesn't see the sourcemaps. Attach doesn't work at all. Appreciate any help
Here is the package.json:
{
"name": "code-ui",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "^2.4.0",
"@angular/compiler": "^2.4.0",
"@angular/core": "^2.4.0",
"@angular/forms": "^2.4.0",
"@angular/http": "^2.4.0",
"@angular/platform-browser": "^2.4.0",
"@angular/platform-browser-dynamic": "^2.4.0",
"@angular/router": "^3.4.0",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/cli": "1.0.0-beta.31",
"@angular/compiler-cli": "^2.4.0",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.0"
}
}
and here is the launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
}
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"url": "http://localhost:4200",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
}
}
]
}
just want to mention that with current version I have still to delete the %temp% folder on win64 to get the breakpoints working correct
Having the same issue with latest version of Angular CLI, Issues seems to still exist, I needed to use the custom launch.json and not the automatically created version as mentioned above by kiranj321
Got the breakpoints hitting in Angular TypeScript files of basic CLI project with the latest stable versions as of 04/Mar/2017:
- @angular/cli: 1.0.0-rc.1
- VS Code 1.10.1
- Extension: Debugger for Chrome v2.6.0
- Window 10, Chrome Version 56.0.2924.87 with shortcut arguments chrome.exe --remote-debugging-port=9222
ng serveornpm startwhich runs by default onhttp://localhost:4200- Run Debugger with 'Launch Chrome 4200' below
{
"name": "Launch Chrome 4200",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
}
Notes:
- Had to close/reopen Chrome from the updated shortcut
- After running
ng serveI went to http://localhost:4200/ in Chrome tab. Ran Launch Chrome 4200 debugger in VSCode, which opened a second tab (no debugging worked in the second tab). If I changed a source file, the breakpoint hit, but the session was attached to the first tab, and I could close the second tab at that point. The breakpoints hit consistently after this - This was with the default
ng new PROJECT_NAMEproject, with no other config changes, and the breakpoints were in a few extra functions I added toapp.component.tsandmain.ts
Working on:
OS : Arch Linux(4.9.11-1-ARCH) Executable : Google Chrome 57.0.2986.0 (Official Build) dev (64-bit) VSCode : 1.7.2
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"runtimeExecutable": "google-chrome-unstable",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
}
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
}
]
}
In Ubuntu 16.10 ` { "name": "Launch Chrome against localhost, with sourcemaps", "type": "chrome", "request": "launch", "url": "http://localhost:4200/", "sourceMaps": true, "webRoot": "${workspaceRoot}", "diagnosticLogging": true, "runtimeExecutable": "/usr/bin/chromium-browser",
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
},
"userDataDir": "${workspaceRoot}/.vscode/chrome"
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"url": "http://localhost:4200/",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
},
"userDataDir": "${workspaceRoot}/.vscode/chrome"
}`
For anyone still having this issue, add the "trace": true setting to the launch config (trace replaces diagnosticLogging in the latest Code / Chrome Debugger releases). Only then is the vscode-chrome-debug.txt file written to disk. It can be found in C:\Users\[username]\.vscode\extensions\msjsdiag.debugger-for-chrome-X.Y.Z\.
Just search for the name of one of your project's source files in there. You'll see if the path mapping between the webpack URL and on-disk source files is right or not.
Looking at the mapping, I saw that the extension was trying to read source files from my dist folder (my web root), which is obviously wrong in my case.
Armed with that new knowledge, I ended up using this to "go back" to my workspace root, which worked perfectly:
"webpack:///*": "${workspaceRoot}/*"
Just make sure to use ${workspaceRoot} or a relative path, not an absolute path! (for portability reasons)
anyone got this to work on OSX?
Lucky one here. On Windows 10, ng-cli, webpack & Chrome hitting breakpoints, live reloading... essentially all stuff you get working with the CLI plus full debugging experience with VS Code.
- Windows 10 Pro (x64) Creators Update v1703 (15063.447)
- VS Code v1.13.1 (Shell v1.6.6 & Node v7.4.0)(Angular Language Service v0.1.4)
- VS Chrome Debugger v3.1.6
- Chrome v59.0.3071.115 (x64)
- Angular CLI v1.1.3 (Node v6.10.1)
My launch.json configuration is as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome with ngCli@4200",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200/",
"sourceMaps": true,
"webRoot": "${workspaceRoot}/src",
"sourceMapPathOverrides": {
"webpack:///C:*":"C:/*"
},
"userDataDir": "C:\\temp\\chromeDummyDir",
"runtimeArgs": [
"--disable-session-crashed-bubble",
"--disable-infobars"
]
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
/*"diagnosticLogging": true,*/
"webRoot": "${workspaceRoot}/src",
"url": "http://localhost:4200/*",
"sourceMapPathOverrides": {
"webpack:///C:*":"C:/*"
}
}
]
}
This is @rodries configuration suggestions. The only thing that isn't working are the crashed bubbles and infobars arguments for Chrome. The thing still says that Chrome didn't shut down properly and stuff like that (in my case it even suggests to translate, i don't care putting the args for that). Everything works.
Everything Angular CLI does works great: live reloading, webpack, etc. When running this configuration i was already running ng serve -o. Steps:
ng serve -o- Debug in VS Code with Launch Chrome with ngCli@4200
Hope this awesome magic trick doesn't fade away with a new update.
I have adopted
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
}
Breakpoints seem to work, but I still get the following lines:
SourceMaps.loadSourceMapContents: Could not download sourcemap from chrome-extension://elgalmkoelokbchhkhacckoklkejnhcd/build/content-script.js.map
SourceMaps.loadSourceMapContents: Could not download sourcemap from chrome-extension://elgalmkoelokbchhkhacckoklkejnhcd/build/ng-validate.js.map
SourceMaps.loadSourceMapContents: Could not download sourcemap from chrome-extension://elgalmkoelokbchhkhacckoklkejnhcd/build/backend.js.map
I'm with the same problem.
I'm using the "trace" config and the configuration is like:
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 9222,
"sourceMaps": true,
"url": "http://localhost/sustentacao/nx/default.aspx#!/*",
"trace": true,
"sourceMapPathOverrides": {
"http://localhost/sustentacao/nx/default.aspx#!/controles/*":"${workspaceRoot}\\folders\\js\\appcontroles\\*"
}
And, in the debug file i'm having a lot of messages of this type:
Paths.scriptParsed: could not resolve http://localhost/sustentacao/nx/js/app/controles/pesquisas/aereas/ctrlAereas2.js?v=20180328082404 to a file under webRoot: undefined. It may be external or served directly from the server's memory (and that's OK).
Anyone can help?
In my case the problem was caused by the backward slash after webpack. I could solve it like this (note the escaped \ after webpack):
{
...
"sourceMaps": true,
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
"webpack:\\*": "${workspaceFolder}/*"
}