Angular "Cannot find module '@angular/core'" in CI
The build tried to resolve an @angular package that is not present in node_modules. In CI this almost always means the install step was skipped, failed silently, or ran in a different job without a shared node_modules.
What this error means
ng build or a tsc step fails with "Cannot find module '@angular/core' or its corresponding type declarations" while the same command works locally.
Error: Cannot find module '@angular/core'
Require stack:
- /home/runner/work/app/app/node_modules/@angular-devkit/build-angular/...Common causes
Dependencies were never installed on this job
The build ran before npm ci, or a separate CI job did not restore node_modules, so @angular packages are missing.
A partial or failed install left node_modules incomplete
An install that errored midway (network, disk) leaves some @angular packages absent even though the job appeared to continue.
How to fix it
Install with npm ci before the build
- Ensure a step runs
npm ci(using the committed lockfile) before any ng command. - If build and install are separate jobs, cache or upload node_modules between them.
- Fail the job on a non-zero install exit code so a partial install does not continue.
- run: npm ci
- run: npx ng build --configuration productionVerify the package is a real dependency
Confirm @angular/core is listed in package.json dependencies and present in the lockfile, not only installed transiently on a dev machine.
npm ls @angular/coreHow to prevent it
- Always run npm ci in the same job that builds.
- Cache node_modules or the npm cache with a lockfile-hashed key.
- Treat a failed install as a hard job failure.