Skip to content
Latchkey

Cloudflare Workers Miniflare "No such module" at runtime in CI

Miniflare runs the worker inside workerd, the same runtime as production. When the bundle imports a module that was not bundled or that relies on a Node built-in without the nodejs_compat flag, workerd throws "No such module" at runtime.

What this error means

A Workers integration test under Miniflare (or vitest-pool-workers) fails with "Error: No such module 'X'." even though the import looks correct in source.

cloudflare
Error: No such module "node:crypto".
  imported from "worker.js"

Diagnose it: credentials and state before configuration

Infrastructure jobs fail on access far more often than on configuration. Confirm the runner can authenticate and reach remote state before reading the plan.

Terminal
# who am I on this runner?
<cloud-cli> auth list 2>/dev/null || <cloud-cli> sts get-caller-identity

# can the backend be reached and locked?
terraform init -backend=true -input=false

Common causes

A Node built-in without nodejs_compat

The worker imports node:crypto/node:buffer etc., but the nodejs_compat compatibility flag is not enabled, so workerd has no such module.

An unbundled dependency

A dependency was not included in the bundle Miniflare loads, so the import cannot be resolved at runtime.

How to fix it

Enable nodejs_compat

Turn on the Node compatibility flag so Node built-ins resolve under workerd.

wrangler.toml
compatibility_flags = ["nodejs_compat"]

Bundle the dependency

  1. Confirm the module is a real dependency and installed.
  2. Ensure your build bundles it into the worker rather than leaving it external.
  3. Re-run the Miniflare test.

How to prevent it

  • Enable nodejs_compat when using Node built-ins.
  • Bundle all runtime dependencies into the worker.
  • Run Workers tests under Miniflare so runtime resolution is exercised.

Frequently asked questions

What causes Cloudflare workers miniflare "No such module" at runtime in CI?
There are 2 common causes: a node built-in without nodejs_compat and an unbundled dependency. The worker imports node:crypto/node:buffer etc., but the nodejs_compat compatibility flag is not enabled, so workerd has no such module.
How do I fix Cloudflare workers miniflare "No such module" at runtime in CI?
There are 2 fixes depending on which cause you have: enable nodejs_compat and bundle the dependency. Work through them in order, since the first is the most common.
What does Cloudflare workers miniflare "No such module" at runtime in CI actually mean?
A Workers integration test under Miniflare (or vitest-pool-workers) fails with "Error: No such module 'X'." even though the import looks correct in source.
How do I stop Cloudflare workers miniflare "No such module" at runtime in CI happening again?
Enable nodejs_compat when using Node built-ins. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card