Skip to content
Latchkey

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:

  1. Set the CI Node version to one that supports the node: protocol.
  2. Re-run so the builtin resolves.
GitHub Actions
- uses: actions/setup-node@v4
  with:
    node-version: 20

Externalize node builtins in the bundler

  1. Mark core modules as external so the bundler leaves node: imports untouched.
  2. 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

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