Node "Error: Cannot find module 'X'" in CI - Fix Module Resolution
Cannot find module means Node started running your code but require() resolved a path that does not exist on disk in CI, even if it works locally.
What this error means
A node script starts, then throws Error: Cannot find module with a require stack pointing at one of your own files or a dependency. It often passes locally but fails on a clean CI checkout.
node
Error: Cannot find module './utils/format'
Require stack:
- /home/runner/work/app/app/src/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)Common causes
A path that only resolves because of local case-insensitivity
macOS and Windows filesystems are case-insensitive, so ./Utils/Format resolves locally but fails on the case-sensitive Linux CI runner.
The compiled output was never built
The script requires a file under dist/ or build/ that the CI job never produced because the build step was skipped or failed silently.
How to fix it
Match the path exactly, including case
- Compare the required path against the real filename letter by letter.
- Fix any case mismatch so it resolves on a case-sensitive Linux filesystem.
- Commit the corrected import and re-run the job.
Ensure the build runs before the script
- Confirm the dist/ or build/ directory the script needs is produced earlier in the job.
- Add the build step before the failing run step.
GitHub Actions
- run: npm run build
- run: node dist/index.jsHow to prevent it
- Use case-sensitive paths everywhere, keep build output out of git, and order CI steps so every required artifact is produced before the script that consumes it.
Related guides
Node ERR_MODULE_NOT_FOUND on ESM Import in CI - Fix Specifier ResolutionFix the Node.js ERR_MODULE_NOT_FOUND error in CI by adding the missing file extension or correcting the ESM i…
Node "Cannot find module 'node:X'" in CI - Fix the Builtin ImportFix the Node.js "Cannot find module node:X" error in CI by upgrading to a Node version that supports the node…
Node "Cannot find package 'X' imported from" in CI - Fix the ESM Package ResolutionFix the Node.js "Cannot find package X imported from" ESM error in CI by installing the dependency or correct…