Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

The command npm run build -- --prod exited with code 1 (Angular)

ErrorThe command "npm run build -- --prod" exited with code 1

Short answer

Exit code 1 only says the build failed; the real message is above it. For Angular the usual cause is the --prod flag, which the CLI removed in favour of --configuration production. The second is a Node.js version outside the range your Angular supports. Run the build by hand to read the message.

  • Applies to Angular 20, Angular 21, Node.js 22, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the same build in a terminal and read the first error, not the last line. Skip the --prod flag to see whether the build itself works.

    node -v
    npx ng build --configuration production
  2. 2Match what you see, then jump to its fix

    1. 1The first error line complains about the flag or an unknown argument, and nothing compilesThe --prod flag no longer existsFix
    2. 2A syntax error or an engine message right at the start of the build, only on the server or in CIThe build machine runs a Node.js version Angular does not supportFix

What does the error look like?

  • The command "npm run build -- --prod" exited with code 1

Cause 1 of 2

The --prod flag no longer exists

1Check

Find where the flag is set: in the CI or publish step, or inside package.json scripts.

grep -rn -e "--prod" package.json angular.json *.yml *.csproj 2>/dev/null

2Fix

The Angular CLI project removed the deprecated --prod option from all builders and says to use --configuration production, or -c production, when the builder's default is not production. Change the script.

"scripts": {
  "build": "ng build",
  "build:prod": "ng build --configuration production"
}

3Verify

Run the new script. It should end with the output path and exit 0.

npm run build:prod
echo $?

Confirmed by github.com

Did this fix it?

Cause 2 of 2

The build machine runs a Node.js version Angular does not support

1Check

Compare node -v on the build machine with the Node.js range for your Angular major in the version table.

node -v

2Fix

Install a version from the range, for example Node.js 22 for Angular 19 to 21, and make the build use it.

nvm install 22 && nvm use 22

3Verify

Run the build again on that machine.

npm ci && npm run build

Confirmed by angular.dev

Did this fix it?

How do I stop it coming back?

  • Name the production build in package.json, so no tool has to pass flags with a double dash.
  • Pin the Node.js version in CI to the same major as your laptop.
  • Use npm ci in build steps so versions match the lockfile.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.