Node "Cannot find module 'node:X'" in CI - Fix the Builtin Import
The node: prefix is the explicit way to import core modules. If Node cannot find node:fs, the runtime is too old to understand the protocol, or a bundler mishandled it.
What this error means
A node process throws Error: Cannot find module node:something for a core module like node:fs or node:path. The same import works on a newer Node locally.
node
Error: Cannot find module 'node:fs/promises'
Require stack:
- /home/runner/work/app/app/src/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:902:15)Common causes
The CI Node version predates node: protocol support
The node: import scheme was added in newer Node; an older runner cannot resolve it and treats it as a missing package.
A bundler did not externalize the builtin
A bundle tried to resolve node:fs as a file instead of marking it external.
How to fix it
Pin a Node version that supports node:
- Set the CI Node version to one that supports the node: protocol.
- Re-run so the builtin resolves.
GitHub Actions
- uses: actions/setup-node@v4
with:
node-version: 20Externalize node builtins in the bundler
- Mark core modules as external so the bundler leaves node: imports untouched.
- Rebuild and re-run.
esbuild config
// esbuild
external: ['node:*']How to prevent it
- Pin the CI Node version with engines and setup-node, and keep bundler externals in sync with the Node features your code targets.
Related guides
Node "The engine 'node' is incompatible" at Runtime in CI - Align Node VersionsFix the "engine node is incompatible" error in CI by pinning the CI Node version to satisfy the engines field…
Node "Error: Cannot find module 'X'" in CI - Fix Module ResolutionFix the Node.js "Error: Cannot find module" crash in CI by correcting the path, extension, or build output th…
Node Build Flag Rejected as "bad option" in CI - Fix the Build InvocationFix a build step where Node rejects a flag as "bad option" in CI by aligning the Node version with the build…