Reputation: 1653
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
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
Reputation: 4588
Since Angular 15 ng build
is similar to ng build --configuration production
Upvotes: 10
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
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
Reputation: 2953
I had the same issue with the --prod command, below is the reason it's not working.
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
Upvotes: 33