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.
✘ [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
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]Replace unsupported APIs with Workers equivalents
- Identify which dependency imports the unsupported built-in.
- For file access, store data in KV, R2, or D1 instead of the file system.
- 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.