One of the most commonly encountered errors while running the ng build command in Angular is Error: Unknown argument: prod.
In Angular, the ng build
command is used to build your Angular application and generate the necessary files that can be deployed to a web server or hosting platform.
But when you run the ng build
command with the --prod
option to make a build for production, you probably encounter an error in the CLI.
Why do you get an Error on Running ng build –prod?
The reason behind getting the Error: Unknown argument: prod error in your Angular application when you run the ng build –prod command is that the –prod option has been deprecated since Angular version 12 and it has been completely removed since Angular version 14.
So, if you are using Angular version 14 or later, you will encounter this error while running the ng build
command with --prod
option.
Solution to Fix the ng build –prod Command Error
To fix the Error: Unknown argument: prod error, you have to pass the option –configuration production instead of –prod.
This will run successfully if you are using Agular version 14 or later.
Here is the full command to make a production build for your Angular application:
ng build --configuration production
On running the above command, the Angular CLI will start making the production build for you which you can upload to the server and make your application live.
All the build files are by default stored inside the /dist folder of the root directory of your application. You can copy and upload them to your live server.
This is how a typical CLI looks like after running the ng build –configuration production command:
I hope this helps. Thanks for reading!