102

When I try to build my angular project in production environment:

ng build --prod --aot

the console returns this error:

Error: Unknown argument: prod

ng serve is working fine and ng build without parameters seems to work too. Why does angular return such an error?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Max Himes
  • 1,133
  • 2
  • 3
  • 11

6 Answers6

212

The reason for this error is the command --prod is deprecated since Angular 12 and removed in Angular 14 based on this Angular-Deprecated APIs and features.

Use --configuration production instead.

So the command will be:

ng build --configuration production
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Nabeeh_Sawaf
  • 2,136
  • 1
  • 4
  • 8
  • 1
    YSK VS2022's Angular template still uses --prod but it also has Angular 13. If you update to 14 or bring your own Angular 14 project you can update the --prod in the .csproj file. Double clicking the "Unknown argument: prod" error will take you right to the liune to change. – user169771 Sep 22 '22 at 14:42
  • 2
    you think that might have deserved a mention in the official update guide... – scy Oct 21 '22 at 06:53
  • In my case Error: Invalid values: Argument: project, Given: "dev", Choices: "demoProjectName" showing... "ng build --configuration production dev" this command i am using – Suresh Panigrahi Jul 19 '23 at 07:02
  • @SureshPanigrahi you cannot have 2 configurations at the same time, production and dev are 2 separate configs that should be declared in the angular.json file, check that file and see the options in there is all. and to be more clear "ng build --configuration production" builds for production environment "ng build --configuration dev" (if defined in the angular.json correctly like that) will build for the development environment. – Nabeeh_Sawaf Jul 22 '23 at 12:50
38

ng build --configuration production --aot can help.

Eugene
  • 1,242
  • 1
  • 10
  • 15
24

I had the same issue with the --prod command, below is the reason it's not working.

enter image description here

Ref: https://angular.io/guide/deprecations#angularcli

New command: ng build --configuration production

Another way you can add this command in the script section in your package.json

Now just run npm run build-prod

enter image description here

Abdullah
  • 2,393
  • 1
  • 16
  • 29
6

you can also use:

ng build -c production
Ivan Tarskich
  • 1,332
  • 1
  • 12
  • 19
UglyIgloo
  • 61
  • 1
  • 2
1

Since Angular 15 ng build is similar to ng build --configuration production

enter image description here

Juan Reina Pascual
  • 3,988
  • 7
  • 21
  • 34
0

I had same problem because recently updated angular version from 12 to 15 and when I build on Azure Dev Ops Pipeline, I was getting error

from <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
to <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build --prod" />

In csprog file.

greybeard
  • 2,249
  • 8
  • 30
  • 66
Muhammad Bilal
  • 1,008
  • 13
  • 14