Angular "Cannot find module @angular/compiler-cli" - Fix in CI
The Angular AOT build needs @angular/compiler-cli. It is missing from node_modules, or its version does not match @angular/core, so the compiler cannot load.
What this error means
The build fails with Cannot find module '@angular/compiler-cli' or a version-mismatch error against @angular/core.
Error: Cannot find module '@angular/compiler-cli'
Require stack:
- /app/node_modules/@angular-devkit/build-angular/src/...Common causes
compiler-cli not installed
The package is missing as a devDependency or was pruned by a production-only install.
Version mismatch with @angular/core
compiler-cli and core are on different Angular versions, so the compiler refuses to load.
How to fix it
Install a matching compiler-cli
- Install @angular/compiler-cli at the same version as @angular/core.
npm install -D @angular/compiler-cli@$(npm ls @angular/core --json | node -e "process.stdout.write(JSON.parse(require('fs').readFileSync(0)).dependencies['@angular/core'].version)")Keep dev deps for the build
- Do not omit dev dependencies before ng build.
npm ci # not --omit=devHow to prevent it
- Upgrade all @angular/* packages together to keep versions aligned.
- Run the build job with dev dependencies installed.