Angular Error: Unknown argument: prod when running ng build

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
3 min

banner

# Angular Error: Unknown argument: prod when running ng build

The Angular "Error: Unknown argument: prod" occurs because the --prod option has been deprecated starting with Angular 12 and is removed in Angular 14.

To solve the error, set the --configuration option to production.

angular error unknown argument prod

Open your terminal in your project's root directory (where your package.json file is) and issue the following command instead.

shell
npx ng build --configuration production

set configuration option to production

The ng build command is used to compile an Angular application or library.

The command outputs the build files into a dist/ directory.

angular dist directory

We used the --configuration option when issuing the command.

The option is used to specify one or more build configurations as a comma-separated list as specified in the configuration section in your angular.json file.

configurations section in angular json

The --configuration option can also be set using the -c alias.

The following 2 commands are equivalent.

shell
npx ng build --configuration production npx ng build -c production

issue ng build command with c alias set to production

The --prod option was deprecated in Angular version 12 and was then removed in Angular version 14.

You can check the version of your Angular CLI by issuing the following command.

shell
ng version

print angular version

As shown in the previous commands, the --prod option has been replaced by --configuration production.

shell
npx ng build --configuration production npx ng build -c production

You can view all of the other options the ng build command supports in this table in the Angular CLI docs.

# Adding a production script to your package.json file

An alternative to manually setting the --configuration option to production is to define a production or build-production script in your package.json file.

Open your package.json file and add the following prod script to your scripts object.

package.json
{ "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test", "prod": "ng build --configuration production" }, }

add prod script to package json

The prod script issues the ng build command with --configuration set to production.

Now you can issue the npm run prod command to compile your Angular application.

shell
npm run prod

issue npm run prod command to compile angular app

# Updating your version of the Angular CLI

If the error persists, try to update your version of the Angular CLI.

Open your terminal and issue the following command.

shell
npm install -g @angular/cli@latest

If you get a permissions error, prefix the command with sudo (on macOS or Linux) or open CMD as an administrator (on Windows).

shell
# for macOS or Linux sudo npm install -g @angular/cli@latest

Once you update your Angular CLI, try to rerun the ng build command.

shell
npx ng build --configuration production

set configuration option to production

If you get the error This command is not available when running the Angular CLI outside a workspace, click on the link and follow the instructions.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.