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

[v9] "optimization": true breaks sourcemaps?

Open mstawick opened this issue 6 years ago • 28 comments

🐞 Bug report

Command (mark with an x)

  • [ ] new
  • [x] build
  • [ ] serve
  • [ ] test
  • [ ] e2e
  • [ ] generate
  • [ ] add
  • [ ] update
  • [ ] lint
  • [ ] xi18n
  • [ ] run
  • [ ] config
  • [ ] help
  • [ ] version
  • [ ] doc

Is this a regression?

Yes, it was fine with v8

Description

There's a question mark, because either sourcemaps are broken, or my understanding of how they work is wrong. Here's my use case and "investigation".

I'm using Sentry for crash-tracking and for production builds I generate source maps and upload them directly to sentry. After switching to v9, all the resolved stack traces were wrong (ie. resolved methods are something else then they should be) - it's all garbage. After going back-and-forth, I've discovered that everything works fine if I disable optimization flag.

So I've created a simple project (ng new), add a small piece of code (button + onclick handler) and generated a production build with optimization enabled (ng build --prod --source-map). I've then decoded the map file using @bengourley/source-map-decoder and compared mapping with the actual minified js file. Turns out column number from the mapping is nowhere close to the actual code it should point to.

🔬 Minimal Reproduction

I've attached a reproduction. Inside is a folder help that contains files I've investigated - the main bundle, it's source map, decoded version, and relevant entries.

sourcemap-bug.zip

🌍 Your Environment


Angular CLI: 9.0.1
Node: 12.14.1
OS: linux x64

Angular: 9.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.1
@angular-devkit/build-angular     0.900.1
@angular-devkit/build-optimizer   0.900.1
@angular-devkit/build-webpack     0.900.1
@angular-devkit/core              9.0.1
@angular-devkit/schematics        9.0.1
@angular/cli                      9.0.1
@ngtools/webpack                  9.0.1
@schematics/angular               9.0.1
@schematics/update                0.900.1
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

mstawick avatar Feb 10 '20 10:02 mstawick

@mkhodan For myself I found the problem was coming from codeCoverage. I remove it from test in angular.json file and now I can debug unit tests like before.

scote avatar May 26 '20 13:05 scote

@scote Thank you so much! It works for me now.

mkhodan avatar May 26 '20 13:05 mkhodan

@mkhodan took me awhile to find a fix/workaround to this issue. Before I found this debugging unit tests was impossible.

scote avatar May 26 '20 14:05 scote

Hence, does codeCoverage break the source maps? :confused:

tonivj5 avatar May 26 '20 14:05 tonivj5

Yes , for Angular 9 when debugging unit tests.

scote avatar May 26 '20 15:05 scote

@scote Thanks!

grzesiek110 avatar May 27 '20 12:05 grzesiek110

So is there an issue open for codeCoverage: true breaking the source maps?

sdesmond avatar Jun 26 '20 03:06 sdesmond

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.