Skip to content

fix commonjs require of unenv aliases in cloudflare worker bundling - #6950

Open
beeirl wants to merge 1 commit into
anomalyco:devfrom
beeirl:worker-alias-interop
Open

fix commonjs require of unenv aliases in cloudflare worker bundling#6950
beeirl wants to merge 1 commit into
anomalyco:devfrom
beeirl:worker-alias-interop

Conversation

@beeirl

@beeirl beeirl commented Jul 22, 2026

Copy link
Copy Markdown

the cloudflare worker bundler passes unenv aliases straight to esbuild. any commonjs dep that requires an aliased shim (debug, inherits, node-fetch, ...) gets the esm namespace object instead of the default export, which breaks at runtime and fails the upload with error 10021. one example: hash.js does require("inherits"), aliased to the esm-only unenv/npm/inherits, so utils.inherits is an object instead of a function.

this adds an esbuild plugin that routes require() resolutions of unenv/npm/* and unenv/mock/* aliases through a small cjs facade: default export when present, named exports copied over. esm imports keep the existing alias behavior. same approach wrangler ships since cloudflare/workers-sdk#6932.

verified with go test ./pkg/runtime/worker, the regression test bundles and executes default export, named export, and esm cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant