Skip to content
Latchkey

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.

Node output
Error: Cannot find module 'node:test'
Require stack:
- /app/test/example.test.js
# running on Node 16, where node:test is unavailable

Common 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.

Workflow
- uses: actions/setup-node@v4
  with:
    node-version: 20   # or the LTS that supports node:test, etc.

Avoid the API on old runtimes

  1. If you cannot upgrade, use the equivalent that exists on your Node version.
  2. Pin a dependency major that still supports your Node line.
  3. 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.

Related guides

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