NestJS "Cannot find module '@nestjs/...'" in CI
Node could not resolve a @nestjs/* package at runtime. In CI this almost always means node_modules was not installed cleanly, not that the import is wrong.
What this error means
The app or test crashes at startup with "Error: Cannot find module '@nestjs/common'" (or /core, /config). It runs locally where node_modules already exists.
Node
Error: Cannot find module '@nestjs/config'
Require stack:
- /home/runner/work/app/app/dist/app.module.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)Common causes
Dependencies were not installed before the step
The build or test step ran before npm ci, or a caching step restored a partial node_modules missing the package.
The package is a peer or unlisted dependency
A @nestjs/* package (like @nestjs/config) is used but never added to package.json, so a clean CI install omits it.
How to fix it
Install with a clean lockfile install
- Run
npm ci(not a cached copy) before build and test steps. - Confirm the package is a declared dependency, not just present locally.
- Re-run so the module resolves from a fresh node_modules.
.github/workflows/ci.yml
- run: npm ci
- run: npm run buildAdd the missing @nestjs package
Install the package explicitly so it is in package.json and restored in CI.
Terminal
npm install @nestjs/configHow to prevent it
- Use
npm ciin CI so installs match the committed lockfile. - Keep every imported @nestjs package as a declared dependency.
- Cache only node_modules keyed on the lockfile hash, and install on a miss.
Related guides
NestJS "nest: command not found" (@nestjs/cli) in CIFix "nest: command not found" in CI - the @nestjs/cli is a devDependency that was not installed, or the build…
NestJS "class-validator" / "class-transformer" not installed in CIFix NestJS class-validator/class-transformer not installed in CI - ValidationPipe needs both packages, and a…
NestJS ConfigModule env var undefined in CIFix NestJS ConfigModule env vars being undefined in CI - the .env file is not committed and the runner has no…