Home > OS >  ng build --prod Error: Unknown argument: prod
ng build --prod Error: Unknown argument: prod

Time:08-11

I have been running this command to build my project anytime i make changes:

ng build --prod --aot=false --build-optimizer=false

This has been working great until I made a mistake today. I ran npm i --save-dev @angular-devkit/build-angular under the /src/app folder by accident. I then ran npm uninstall @angular-devkit/build-angular under that folder and under the project root folder, and ran that npm i --save-dev @angular-devkit/build-angular under the root folder.

Now when I am trying to build the project with the first ng build command I provided above I get the Error: Unknown argument: prod.

When I run just ng build I get the following error:

This version of CLI is only compatible with Angular versions ^14.0.0, but Angular version 6.1.10 was found instead.

Any ideas as to how I can fix this?

CodePudding user response:

Your first error occurs because option --prod is removed in Angular 14 and deprecated since version 12, you can fix it by replacing it with --configuration "production"

Details see for example here: https://lachimi.com/angular/option-prod-is-deprecated-Use-configuration-production-instead

Your second error is kind of self explaining, your CLI version is too new for the used Angular version. You could either trying to upgrade one or downgrade the other.

If you upgrade your Angular version you might run into problems with other dependencies in your project and might also need to upgrade them.

CodePudding user response:

Changed my versions in package.json back to their old values and it's working now:

 "@angular-devkit/build-angular": "~0.8.0",
 "@angular/cli": "~6.2.9",
  • Related