Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 12 source map is missing in browser

We have upgraded to Angular 12 recently and facing a problem wherein the browser Source Map is missing and due to this we are unable to debug our component files as there aren't any. Can anyone suggest what I am missing?

like image 256
ammad khan Avatar asked May 22 '21 08:05

ammad khan


People also ask

How do I enable source maps?

To enable source maps in Google Chrome, go to Developer Tools, click the little cog icon, and then make sure that “Enable Javascript source maps” is checked. That's it.

What is Sourcemap in angular?

At its core, a source map is a JSON file that contains all the necessary information to map the transpiled code back to the original sources. Pretty cool! Technically a source map is just a JSON file that contains the following fields: version: indicates the source map spec version.

What is TypeScript source map?

Explanation: TypeScript Map files are source map files that let tools map between the emitted JavaScript code and the TypeScript source files that created it. And these Source Map files will then help to debug the Typescript file instead of debugging the emitted JavaScript file.


2 Answers

Angular 12 changed the default "ng build" to use the "production" configuration. You want "sourceMap" so try adding a "development" config in your angular.json like this

"development": {   "buildOptimizer": false,   "optimization": false,   "vendorChunk": true,   "extractLicenses": false,   "sourceMap": true,   "namedChunks": true } 

Target with either "ng build -c development", or change your default configuration for "ng serve" eg.

"serve": {   "builder": "@angular-devkit/build-angular:dev-server",   "options": {     "browserTarget": "app:build"   },   "configurations": {     "production": {       "browserTarget": "app:build:production"     },     "development": {       "browserTarget": "app:build:development"     }   },   "defaultConfiguration": "development" }, 
like image 167
colche Avatar answered Sep 17 '22 16:09

colche


Please add: "sourceMap":true and "optimization":false under architect -> build-> options in your angular.json.

Do not forget to set these for your production configurations the other way around.

like image 40
István Herbák Avatar answered Sep 18 '22 16:09

István Herbák