Last updated: Apr 4, 2024
Reading time·3 min
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
.
Open your terminal in your project's root directory (where your package.json
file is) and issue the following command instead.
npx ng build --configuration production
The ng build command is used to compile an Angular application or library.
The command outputs the build files into a 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.
The --configuration
option can also be set using the -c
alias.
The following 2 commands are equivalent.
npx ng build --configuration production npx ng build -c 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.
ng version
As shown in the previous commands, the --prod
option has been replaced by
--configuration production
.
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.
package.json
fileAn 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.
{ "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test", "prod": "ng build --configuration production" }, }
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.
npm run prod
If the error persists, try to update your version of the Angular CLI.
Open your terminal and issue the following command.
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).
# for macOS or Linux sudo npm install -g @angular/cli@latest
Once you update your Angular CLI, try to rerun the ng build
command.
npx ng build --configuration 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.
You can learn more about the related topics by checking out the following tutorials: