Skip to content
Latchkey

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

  1. Run npm ci (not a cached copy) before build and test steps.
  2. Confirm the package is a declared dependency, not just present locally.
  3. Re-run so the module resolves from a fresh node_modules.
.github/workflows/ci.yml
- run: npm ci
- run: npm run build

Add the missing @nestjs package

Install the package explicitly so it is in package.json and restored in CI.

Terminal
npm install @nestjs/config

How to prevent it

  • Use npm ci in 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →