19

I updated Angular project from Angular 10 to 11x. Everything works normally, except for one warning on running project using ng serve (without any option in ng serve). The warning is:

Option "sourceMap" is deprecated: Use the "sourceMap" option in the browser builder instead.

The warning is not presented in ng build.

Here is how browser builder part in angular.json of the project looks like:

"builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/my-app",
            "index": "src/index.html",
            "sourceMap": true,
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],

Something related has changed in Angular 11? How to remove this warning?

4
  • What is your "serve" section in angular.json? Commented Apr 2, 2021 at 14:26
  • I actually tried the configuration you posted and I dont get the same warning. I don't think its relevant Commented Apr 2, 2021 at 15:38
  • @HTN, here is "serve" section in my angular.json: "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "my-app:build", "sourceMap": { "scripts": true, "styles": true, "vendor": true } }, "configurations": { "production": { "browserTarget": "easyproduction-web:build:production" } } }, Commented Apr 2, 2021 at 17:03
  • I don't understand the question. The warning says: "Option "sourceMap" is deprecated". In your serve configuration you have "sourceMap": { "scripts": true, "styles": true, "vendor": true } }. What exactly is unclear with this warning? Commented Apr 2, 2021 at 17:20

4 Answers 4

14

I was confused by some of the answers, these options aren't really deprecated but should now be specified in the proper "build" section of angular.json, not "serve".

Sign up to request clarification or add additional context in comments.

3 Comments

In "serve" section, it is deprecated: angular.io/cli/serve#options
Yes we agree. Just pointing out that it doesn't mean you can't turn source maps on or off for ng serve, as long as you put it in the right build section. Just wanted to make it clear in case there are other people like me who didn't get it.
Just upgrade to Angular13 from Angular 12 and use to have ng serve --source-map=true --prod=false --watch=true but now it says --source-map is an "unknown option". I have to use ng serve as I have to run HTTPS/SSL locally for our system. But now I have no source maps? Any ideas?
13

You need to remove sourceMap from serve --> options --> sourceMap, which is deprecated.

2 Comments

Rightly pointed out, use of sourceMap is deprecated now: angular.io/cli/serve#options
I didn't have this flag in serve configuration, but suddenly ( after update) debugging stopped working. I found that sourceMaps are not generated anymore. Putting this deprecated flag in solved the issue. What has changed in default sourceMap configuration ?
13

Based on previous comments, here is a working configuration :

In angular.json, add this configuration to projects.[NAME_OF_YOUR_PROJECT].architect.serve.configurations :

"dev": {
  "browserTarget": "[NAME_OF_YOUR_PROJECT]:build:dev"
}

Like that :

...
"architect": {
  "serve": {
    ...
    "configurations": {
      "production": {
        ...
      },
      "dev": {
        "browserTarget": "[NAME_OF_YOUR_PROJECT]:build:dev"
      }
    }
  },
  ...

Then, add the corresponding "dev" configuration in projects.[NAME_OF_YOUR_PROJECT].architect.build.configurations :

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

like this example :

...
"architect": {
  "build": {
    ...
    "configurations": {
      "production": {
        ...
      },
      "dev": {
        "optimization": false,
        "sourceMap": true
      }
    }
  },
...

Now you just have to edit the "start" script command in package.json :

...
"scripts": {
  "start": "ng serve --configuration=dev",
  ...

and you should retrieve sources map files in your favorite browser !

3 Comments

This should be the accepted answer.
Thanks a lot! This helped me fix the problem too, migrating from Angular 10 to Angular 13.
stackoverflow.com/questions/67647471/… this answer helped me. There were more properties that I added in the architect.build.configurations.dev section that fixed my issue
5

Using Angular15 you have to set the sourceMap and similar settings in the angular.json file under

architect -> build -> configurations -> development

then you can load this configuration via serve using the development browserTarget setting it under

architect -> serve -> configurations -> development

angular.json example:

    {
      ...
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            ...
          },
          "configurations": {
            "production": {
              ...
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          ...
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "ng-app-15:build:production"
            },
            "development": {
              "browserTarget": "ng-app-15:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        ...
      }
    }

Then, you can run the following command to use ng serve with sourceMap properly and with the possibility of using the debugger.

ng serve --configuration=developmentstrong text

Note: if this answer will expire for some reason, you can always install the latest version of Angular and run "ng new app", by default it will show you the correct angular.json configurations to use properly sourceMap and similar settings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.