Angular 12 source map is missing in browser
Asked Answered
N

6

73

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?

Nonessential answered 22/5, 2021 at 8:21 Comment(2)
You are not missing anything - the angular framework is missing adequate guidance....Pinite
you are right the documentation needs an upgrade.Nonessential
S
123

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"
},
Stylus answered 26/5, 2021 at 8:31 Comment(7)
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!Pinite
Thank you so much. I have changed my nx config with your answer. Everything is perfect right now.Teledu
Where does the "development" go inside the angular.json?Clippard
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?Brawl
Following this https://mcmap.net/q/275615/-ng-serve-command-show-an-error-first-and-in-last-compiled-successfully still does not fix my issueBrawl
this works well for me 😁😁😁😁Penetralia
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 :-DClump
B
9

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.

Belligerency answered 26/5, 2021 at 8:18 Comment(2)
The above solution worked as well. thanks for coperationNonessential
Solution worked for ionic 6 project too. ThanksCoke
P
3

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.

Partible answered 30/1, 2022 at 6:47 Comment(1)
this worked for my ng build --watch. niceNormalcy
H
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.

Horace answered 19/5, 2022 at 6:20 Comment(0)
B
1

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
}
Beverie answered 19/9, 2022 at 9:51 Comment(0)
C
-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
Chacma answered 12/7, 2021 at 7:45 Comment(1)
Throws the following errors, Invalid tag name "—-from=11", Invalid tag name "—-migrate-only"Dematerialize

© 2022 - 2024 — McMap. All rights reserved.