Nitro · NITRO0024

Guard AsyncLocalStorage#enterWith on Cloudflare

Report AsyncLocalStorage#enterWith() calls whose failure is not handled, outside a try/catch or in one whose catch throws, in code that targets Cloudflare Workers.
NITRO0024vite-doctor/nitroruntimeerrorSuggestion

Run this rule

pnpm vite-doctor . --framework nitro --rules nitro/cloudflare/no-unguarded-als-enterwith

Why it matters

workerd implements AsyncLocalStorage run(), exit(), getStore(), bind(), and snapshot(), but enterWith() throws asyncLocalStorage.enterWith() is not implemented, with nodejs_compat or nodejs_als enabled. Code that works in Node.js then fails the request on Cloudflare. The rule runs when Project Inventory shows a Cloudflare target for the workspace package: a wrangler config, a cloudflare Nitro preset, Cloudflare tooling dependencies such as wrangler or @cloudflare/workers-types, a cloudflare package keyword, or cloudflare: imports in the file.

Run the work inside als.run(store, callback) so the store is scoped to the callback. If the call has to stay for Node.js runtimes, wrap it in try/catch and keep a fallback that does not depend on enterWith().

Example

Scope the store with run()

Before

const eventStorage = new AsyncLocalStorage<H3Event>()

export function enterEvent(event: H3Event) {
  eventStorage.enterWith(event)
}

After

const eventStorage = new AsyncLocalStorage<H3Event>()

export function runWithEvent<T>(event: H3Event, callback: () => T): T {
  return eventStorage.run(event, callback)
}
Copyright © 2026