Skip to content
Latchkey

Cloudflare Workers "Could not resolve 'node:fs'" in CI

The Workers runtime is not Node. Built-ins like node:fs are not available, and fs (file system access) has no Workers equivalent at all. wrangler fails to bundle the import unless a compatible module exists.

What this error means

wrangler deploy fails at bundle time with "Could not resolve 'node:fs'", or at runtime with "No such module 'node:fs'". A dependency reached for a Node API the edge runtime does not expose.

wrangler
✘ [ERROR] Could not resolve "node:fs"

    node_modules/some-lib/index.js:3:18:
      3 │ import fs from "node:fs";
        ╵                   ~~~~~~~~~

Common causes

A dependency uses a Node-only built-in

A library imports node:fs, node:child_process, or similar. Some Node built-ins are polyfilled under nodejs_compat, but file system and process APIs are not.

nodejs_compat is not enabled for built-ins that do exist

Built-ins such as node:buffer or node:crypto need the nodejs_compat flag. Without it, even supported built-ins fail to resolve.

How to fix it

Enable the Node compatibility flag

For Node built-ins that Workers supports, add nodejs_compat and a recent compatibility date so the polyfills are wired in.

wrangler.toml
# wrangler.toml
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]

Replace unsupported APIs with Workers equivalents

  1. Identify which dependency imports the unsupported built-in.
  2. For file access, store data in KV, R2, or D1 instead of the file system.
  3. Swap the dependency for a Workers-compatible one if it cannot run without fs.

How to prevent it

  • Prefer Web-standard APIs (fetch, crypto.subtle) over Node built-ins in Workers.
  • Set nodejs_compat plus a current compatibility date when a dependency needs supported built-ins.
  • Audit dependencies for fs and child_process before adding them to a Worker.

Related guides

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