66

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?

ammad khan
  • 1,022
  • 1
  • 10
  • 14

6 Answers6

116

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"
},
SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
colche
  • 1,184
  • 1
  • 7
  • 2
  • 2
    Thank you! You save many hairs on my head. Seriously this was getting on my nerves and frankly - the angular documentation is ... it needs information like this comment. It is sad when there is more information in stackoverflow rather than the official docs in their webside. Thank you again! – Combine Sep 05 '21 at 08:45
  • Thank you so much. I have changed my nx config with your answer. Everything is perfect right now. – eyupaltindal Oct 21 '21 at 20:07
  • 2
    Where does the "development" go inside the angular.json? – DevEng Nov 07 '21 at 20:04
  • 2
    I have done that but it's weird because I still get the same result. I am on Angular 13 and I'm struggling to get the sourceMaps in order to debug. Anyone has had the issue on the latest Angular? – Carlos Torrecillas Dec 02 '21 at 14:05
  • Following this https://stackoverflow.com/a/70101571/5293466 still does not fix my issue – Carlos Torrecillas Dec 02 '21 at 14:13
  • this works well for me – C Alonso C Ortega Feb 13 '22 at 06:10
  • Thank you VERY much! I spent days to figure out why migrating from Angular 11 to 13 made the "webpack" folder disappear in the browser. I knew my problems would surely be fixed by some simple statement, now I know which one :-D – rawcode Jun 29 '22 at 08:26
6

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.

1

After following @colche answear still i was unable to generate source map, after finding few minuses, I got solution:

ng build --prod --source-map

You have to build with source map.

MD Ashik
  • 9,117
  • 10
  • 52
  • 59
1

If you are using Nx workspace, you need to edit the workspace.json file to add development settings to build:configurations like this:

"build": {
      ...
      "configurations": {
        ...
        "development": {
          "buildOptimizer": false,
          "optimization": false,
          "vendorChunk": true,
          "extractLicenses": false,
          "sourceMap": true,
          "namedChunks": true
        }
      },
      "defaultConfiguration": "production"
    }

and add development under serve:configurations like this and set the defaultConfiguration to development:

     "serve": {
      ...
      "configurations": {
        ...
        "development": {
          "browserTarget": "gt:build:development"
        }
      },
      "defaultConfiguration": "development"
    },

this way serve will always serve in development mode and build will always build in production mode.

0

Using Prod mode use below code inside the configurations.

"production": {
    "sourceMap": false,
    "optimization": true
 }

Using Dev mode use below code inside the configurations.

"development": {
  "sourceMap": true,
  "optimization": false
}
E_net4
  • 27,810
  • 13
  • 101
  • 139
Mr.White
  • 1
  • 1
-1

You can run the below command to update the angular cli. Hope it will fix the issue.

ng update @angular/cli@latest —-from=11 —-migrate-only