Max Himes
Max Himes

Reputation: 1653

ng build --prod => Error: Unknown argument: prod

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?

Upvotes: 154

Views: 146775

Answers (7)

Rory McCrossan
Rory McCrossan

Reputation: 337560

I encountered this error when deploying a legacy Angular solution contained in a .Net project via a Devops pipeline, after updating to Node v20.x.

The fix was to edit the .csproj file to update the Command attribute from the old version, which was this:

<!-- OLD -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

To the new syntax, which is this:

<!-- NEW -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --configuration production" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --configuration production" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

Note the change of --prod to --configuration production.

Upvotes: 0

Juan Reina Pascual
Juan Reina Pascual

Reputation: 4588

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

enter image description here

Upvotes: 10

UglyIgloo
UglyIgloo

Reputation: 71

you can also use:

ng build -c production

Upvotes: 7

Muhammad Bilal
Muhammad Bilal

Reputation: 1152

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.

Upvotes: 0

Nabeeh_Sawaf
Nabeeh_Sawaf

Reputation: 3196

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

Upvotes: 318

Abdullah
Abdullah

Reputation: 2953

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

Upvotes: 33

Eugene
Eugene

Reputation: 1517

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

Upvotes: 46

Related Questions