All guidesMore providers: databases, auth, hosting, email and payments
On this page

Cloudflare Workers error

Cloudflare

Uncaught Error: No such module "node:async_hooks"

By Ohad Krispin, founder of VibeRaven · LinkedIn

"Uncaught Error: No such module "node:async_hooks"." means the Worker imports a Node.js built-in module and the Workers runtime does not provide it, because Node.js compatibility is off. Add "compatibility_flags": ["nodejs_compat"] to your Wrangler config with a compatibility_date of 2024-09-23 or later, then deploy again. Cloudflare turns the flag on by default only for compatibility dates of 2026-08-04 and later, so an older date is the usual cause. Wrangler warns about this at build time for a node: import, and stops the build with "Could not resolve" for an import without the prefix, such as "fs". Reproduced with wrangler 4.156.0 on 2026-10-31.

What do the build and runtime messages look like?

We imported node:async_hooks in a Worker with a compatibility_date of 2025-01-01 and no flags. wrangler deploy --dry-run only warned, so the build passed; the failure came when the Worker started, here under wrangler dev. A second Worker that imported "fs" with no prefix stopped the build. Wrangler builds that note from esbuild's "Could not resolve" error for any Node built-in module name.

On Pages, a developer reports the same module failing at publish time: "Failed to publish your Function. Got error: Uncaught Error: No such module "node:async_hooks"." In workerd issue 5244 (linked in the sources), the same kind of error carried [code: 10021].

[WARNING] The package "node:async_hooks" wasn't found on the file system but is built into node.
  Your Worker may throw errors at runtime unless you enable the "nodejs_compat" compatibility flag.
  Imported from:
   - src\index.ts

[ERROR] Could not resolve "fs"
  The package "fs" wasn't found on the file system but is built into node.
  - Add the "nodejs_compat" compatibility flag to your project.

Uncaught Error: No such module "node:async_hooks".
    imported from "index.js"

Why did it start failing, or why does the flag seem to be ignored?

The Node.js compatibility docs say to add nodejs_compat for compatibility dates from 2024-09-23 through 2026-08-03, and that from 2026-08-04 Workers enable nodejs_compat and nodejs_compat_v2 by default. Wrangler also injects polyfills only when the flag is on and the date is 2024-09-23 or later. A Worker generated with an older date, or a project whose wrangler.toml has no flags, hits this error as soon as a dependency imports node:fs, node:buffer or node:async_hooks.

Some modules are only stubs. Cloudflare lists modules such as node:vm, node:child_process and node:worker_threads that can be imported but do not provide working implementations, each turned on by nodejs_compat from its own date. A package that only loads such a module can need a newer date, and one that calls it will not work.

One report, workerd issue 5244, moved compatibility_date to 2025-09-17 while using nodejs_compat_v2 and got No such module "node:fs". A Cloudflare contributor answered that nodejs_compat turns on the node:fs module flag and nodejs_compat_v2 does not, and advised nodejs_compat. At the time we read it the issue was still open.

How do I enable it for a Pages Function?

Put the same two keys in the Wrangler config file of the Pages project. The Pages docs show compatibility_flags with nodejs_compat in the config, require an explicit compatibility_date there, and say that once a Wrangler file is used the same fields can no longer be edited in the dashboard. In our run wrangler pages functions build printed the same warning for a function that imports node:async_hooks.

{
  "name": "notes-worker",
  "main": "src/index.ts",
  "compatibility_date": "2025-04-01",
  "compatibility_flags": ["nodejs_compat"]
}

Checklist

How to fix it, then check the fix

  1. 01
    Build without deploying. The warning names the file that imports the module:
    npx wrangler deploy --dry-run --outdir dist
  2. 02Add "nodejs_compat" to compatibility_flags in wrangler.jsonc or wrangler.toml, and set compatibility_date to 2024-09-23 or later. In a Pages project, put both in the project's Wrangler file.
  3. 03If the config has nodejs_compat_v2 and a recent compatibility_date, replace it with nodejs_compat.
  4. 04If the only Node API you need is AsyncLocalStorage, the docs also allow compatibility_flags = [ "nodejs_als" ] on its own.
  5. 05Run the dry run again: the "built into node" warning is gone. Then start wrangler dev or deploy, and request the route that failed.

Related

Sources

Official docs behind this checklist

FAQ

FAQ for builders before launch

Do I still need nodejs_compat if my compatibility_date is 2026-08-04 or later?

No. The Cloudflare docs say that for compatibility dates of 2026-08-04 or later, Workers enable nodejs_compat and nodejs_compat_v2 by default. In our run, a Worker with that date and no flags imported node:async_hooks without error.

Why did wrangler print a warning and not an error?

In our run, a node: import only produced a warning and the build passed, while an import without the prefix stopped the build. Either way the runtime fails later if the flag is off, so treat the warning as the error.

What if a package still fails with nodejs_compat on?

Check the module against the support table on the Node.js compatibility page. Some modules are partially supported or only stubs, and a stub can be imported but does not do the work.