20

I did my angular project set up locally on my machine with latest angular version, whenever I run the project with CLI command as ng serve, it shows the error first in red color "This is a simple server for use in testing or debugging Angular applications locally. It hasn't been reviewed for security issues.

DON'T USE IT FOR PRODUCTION!" But in last, all compiled successfully.

My question is, why this error is appearing whenever I run my angular project with "ng serve" on my local machine. please explain in detail. Is there any configuration issues? Do we need to make any changes in our angular set up to avoid such error in the future?

2
  • 1
    You can ignore this warning. Commented Jan 27, 2022 at 11:29
  • I wonder how all these (upvoted!) answers help fixing a non-issue.
    – El Mac
    Commented Feb 19 at 9:49

5 Answers 5

43

If you get the following error on ng serve

angular error

Probably you miss the following configuration into angular.json file:

{
 "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
 .
 .
 .
 "projects": {
    "my-project": {
        .
        .
        .
        "architect": {
            "build": {
                "builder": "@angular-devkit/build-angular:browser",
                "options": {
                      .
                      .
                      .
                 },
                 "configurations": {
                     "production": {
                        .
                        .
                        .
                      },
                      "development": { // add this block
                        "buildOptimizer": false,
                        "optimization": false,
                        "vendorChunk": true,
                        "extractLicenses": false,
                        "sourceMap": true,
                        "namedChunks": true
                      }
                 },
            }
            .
            .
            .
            "serve": {
              "builder": "@angular-devkit/build-angular:dev-server",
              "options": {
                  .
                  .
                  .
              },
              "configurations": {
                "production": {
                  "browserTarget": "my-project:build:production"
                },
                "development": { // add this block
                  "browserTarget": "my-project:build:development"
                }
              },
              "defaultConfiguration": "development" // add this line
            },
            .
            .
            .

Tested on angular 13.*

5
  • With that set up you posted, did you get rid off the message? I did the exact same thing and I still get it. I have Angular 13.0.3 Commented Dec 2, 2021 at 14:09
  • @CarlosTorrecillas Yes, I got rid off the message Commented Dec 3, 2021 at 7:19
  • 1
    Good, thanks! I found out what happened. During an old migration I had an .angular.json and a angular.json which caused trouble. Now is all good Commented Dec 3, 2021 at 8:39
  • 2
    For me works alot this suggestion. Olny thing I have to add, my serve line i had this option "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { //this option "browserTarget": "clinic-web-ui:build:development" }, Commented Dec 3, 2021 at 15:00
  • Worked for me after update for an ionic project. Commented Jun 28, 2022 at 6:21
11

You have done nothing wrong. This is a standard warning. While ng serve is useful for quickly testing/debugging your project, you should never use it in production for any number of security and performance reasons.

5

I faced the same issue. And my fix is:

Go to your angular.json file

Follow the path project->architect->build->configuration->development->optimization to false

4

This error is just to let you know you shouldn't run ng-serve to launch your application for production, this allows for debug mode and quicker building for testing.

If you would like this error to go you can add the --prod meta-flag this will engage the following build optimization features.

  • Ahead-of-Time (AOT) Compilation: pre-compiles Angular component templates.
  • Production mode: deploys the production environment which enables production mode.
  • Bundling: concatenates your many application and library files into a few bundles.
  • Minification: removes excess whitespace, comments, and optional tokens.
  • Uglification: rewrites code to use short, cryptic variable and function names.
  • Dead code elimination: removes unreferenced modules and much unused code.

But will increase the build time.

0

Go into your angular.json file

In that file, follow the path projects -> architect -> build -> options Change buildOptimizer to true and add aot to true as well The above commands should work now.

ADDON: If you have that problem with ng serve or ng test, you could try replacing build in step 2 with serve or test respectively (Disclaimer: I have not tested that).

Not the answer you're looking for? Browse other questions tagged or ask your own question.