Node "Cannot find module 'node:crypto'" - Fix node: Builtins on Old Node in CI
The node: import prefix (e.g. node:crypto, node:fs) is only recognized by newer Node versions. On an older runner Node, the resolver treats node:crypto as a missing package and throws.
What this error means
Code or a dependency importing node:crypto (or node:fs, node:path, …) fails with Cannot find module 'node:crypto' in CI, while it works locally on a newer Node. The tell is the node: prefix and an older runner Node.
Error: Cannot find module 'node:crypto'
Require stack:
- /app/dist/index.js
at Function._resolveFilename (node:internal/modules/cjs/loader)
... code: 'MODULE_NOT_FOUND'Common causes
Runner Node is too old for the node: scheme
The node: builtin prefix is supported from Node 14.18/16+. On an older runner Node, node:crypto is unresolved and throws MODULE_NOT_FOUND.
A dependency upgraded to node: imports
A bumped dependency now uses node:-prefixed builtins; if CI still runs an older Node, that dependency cannot load.
How to fix it
Upgrade CI Node to a supported version
Run a Node version that recognizes the node: builtin scheme.
- uses: actions/setup-node@v4
with:
node-version: 20
- run: node --versionAlign Node with your dependencies
- Set
engines.nodeand.nvmrcto a version supportingnode:builtins. - Upgrade Node in CI when a dependency adopts
node:imports. - Keep local, CI, and prod Node versions in sync.
How to prevent it
- Run a current Node LTS in CI.
- Declare
engines.nodeand use.nvmrc/setup-node. - Bump Node when dependencies require newer builtins.