Node "Cannot find module 'node:…'" - Fix Old Node Version in CI
The node: import prefix and certain builtins (like node:test) exist only on recent Node versions. On an older runtime they resolve to nothing, producing a Cannot find module error for a "builtin".
What this error means
Code or a dependency imports a node:-prefixed builtin (or a newer core module) and Node throws "Cannot find module 'node:...'". It happens when CI runs an older Node than the code or dependency targets.
Error: Cannot find module 'node:test'
Require stack:
- /app/test/example.test.js
# running on Node 16, where node:test is unavailableCommon causes
CI Node is older than the API requires
Features like node:test, or the node: scheme for some builtins, were added in newer Node majors. On an older line they are absent.
A dependency targets a newer Node
An upgraded dependency may use node:-prefixed builtins or new core APIs, requiring a Node version your CI has not moved to.
How to fix it
Upgrade the CI Node version
Run a Node major that includes the builtin/API in use.
- uses: actions/setup-node@v4
with:
node-version: 20 # or the LTS that supports node:test, etc.Avoid the API on old runtimes
- If you cannot upgrade, use the equivalent that exists on your Node version.
- Pin a dependency major that still supports your Node line.
- Set engines.node so installs flag the mismatch early.
How to prevent it
- Keep CI Node aligned with the APIs you use.
- Track engines.node and bump CI in step.
- Prefer an active LTS line in CI.