Search code examples
angularangular-cli

ng build --prod Error: Unknown argument: prod


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?


Solution

  • 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"

    See breaking changes in changelog for version 14: https://github.com/angular/angular-cli/blob/main/CHANGELOG.md#breaking-changes-2

    Your second error is kind of self explaining, your CLI version is too new for the used Angular version. You could either try 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.