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.
angular
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.
Terminal
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.
Terminal
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.
Related guides
Angular "ng: command not found" - Fix in CIFix "ng: command not found" in CI - the Angular CLI is not installed locally, dev deps were skipped, or the s…
Angular AOT Compile Error (NGxxxx) - Fix in CIFix Angular AOT compile errors (NGxxxx) in CI - a template binding, missing declaration, or type error fails…
Angular "Module build failed" - Fix in CIFix "Module build failed" during ng build in CI - a loader, a SCSS error, or a bad import breaks compilation…