Skip to content
Latchkey

Wrangler "nodejs_compat" compatibility flag required in CI

Your Worker imports a Node built-in (such as node:buffer or node:crypto) or an npm package that needs one. Cloudflare only provides these when the nodejs_compat compatibility flag is set. Add it to wrangler.toml so the runtime supplies the Node APIs.

What this error means

The Worker builds but deploy or runtime fails with "No such module \"node:buffer\"" or a hint that Node.js compatibility is not enabled.

wrangler
✘ [ERROR] service core:user:app: Uncaught Error: No such module "node:buffer".
  imported from "index.js"

Common causes

A Node built-in used without the flag

The Workers runtime does not expose Node built-ins by default; importing one without nodejs_compat fails to resolve the module.

An npm dependency assumes Node

A transitive package pulls in node:crypto, node:stream, or similar, which only works with the compatibility flag enabled.

How to fix it

Enable nodejs_compat

Add the flag and use a compatibility_date recent enough to support it.

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

Set the flag per environment

When deploying with --env, named environments need the flag set explicitly.

wrangler.toml
[env.production]
compatibility_flags = ["nodejs_compat"]

How to prevent it

  • Enable nodejs_compat when any dependency imports Node built-ins.
  • Keep compatibility_date recent so the flag is honored.
  • Set the flag in every environment you deploy with --env.

Frequently asked questions

What causes ""nodejs_compat" flag required"?
The Workers runtime does not expose Node built-ins by default; importing one without nodejs_compat fails to resolve the module.
How do I fix "nodejs_compat" flag required?
Add the flag and use a compatibility_date recent enough to support it.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card