Skip to content

Keep Node.js ESM packages working when consumers rebundle them as CommonJS - #15870

Merged
dario-piotrowicz merged 3 commits into
mainfrom
dario/packages-banner
Sep 25, 2026
Merged

dario-piotrowicz merged 3 commits into
mainfrom
dario/packages-banner

Conversation

@dario-piotrowicz

@dario-piotrowicz dario-piotrowicz commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Node.js-targeted ESM bundles now provide a real require implementation for bundled CommonJS dependencies. This avoids downstream patches for dynamic require calls and keeps the packages usable when a consumer rebundles them to CommonJS.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because: clear build output change
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: build output change

A picture of a cute animal (not mandatory, but encouraged)


Devin Review

@changeset-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fe36d81

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@cloudflare/autoconfig Patch
@cloudflare/codemods Patch
@cloudflare/deploy-helpers Patch
@cloudflare/workers-auth Patch
@cloudflare/workers-utils Patch
@cloudflare/remote-bindings Patch
@cloudflare/cli-shared-helpers Patch
@cloudflare/containers-shared Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Sep 25, 2026
@workers-devprod
workers-devprod requested review from a team and cjol and removed request for a team September 25, 2026 11:48
@workers-devprod

workers-devprod commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/cloudchamber
  • ✅ @cloudflare/wrangler
Show detailed file reviewers
  • packages/containers-shared/tsup.config.ts: [@cloudflare/cloudchamber]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Devin Review

Comment thread packages/workers-utils/tsup.config.ts
Comment thread packages/deploy-helpers/tsup.config.ts
@ask-bonk

ask-bonk Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@cloudflare/workers-utils exposes dist/browser.mjs through its browser export condition. This banner is emitted into that entry point too, so browser consumers now receive a static node:module import and browser bundlers reject the package before constructWranglerConfig can be used. Build src/browser.ts separately without the Node-only banner, and keep the banner on the remaining Node entries.

export default defineConfig(() => [
	{
		treeshake: true,
		keepNames: true,
		entry: ["src/browser.ts"],
		platform: "node",
		format: "esm",
		dts: true,
		outDir: "dist",
		tsconfig: "tsconfig.json",
		metafile: true,
		sourcemap: process.env.SOURCEMAPS !== "false",
		define: {
			"process.env.NODE_ENV": `'${"production"}'`,
		},
		external: ["@cloudflare/*", "vitest", ...EXTERNAL_DEPENDENCIES],
	},
	{
		treeshake: true,
		keepNames: true,
		entry: [
			"src/index.ts",
			"src/prometheus-metrics.ts",
			"src/test-helpers/index.ts",
			"src/compliance.ts",
			"src/compatibility-date.ts",
			"src/docker-path.ts",
			"src/errors.ts",
			"src/fs-helpers.ts",
			"src/global-wrangler-config-path.ts",
			"src/local-env.ts",
			"src/zod-format.ts",
		],
		platform: "node",
		banner: {
			js: 'import { createRequire as __createRequire } from "node:module"; const require = __createRequire(typeof __filename === "string" ? __filename : import.meta.url);',
		},
		format: "esm",
		dts: true,
		outDir: "dist",
		tsconfig: "tsconfig.json",
		metafile: true,
		sourcemap: process.env.SOURCEMAPS !== "false",
		define: {
			"process.env.NODE_ENV": `'${"production"}'`,
		},
		external: ["@cloudflare/*", "vitest", ...EXTERNAL_DEPENDENCIES],
	},
]);

@ask-bonk

ask-bonk Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

PR #15870 adds CommonJS require support to Node-targeted ESM bundles.

  1. P1: workers-utils now breaks its browser export by injecting node:module; suggested fix posted.

github run

@pkg-pr-new

pkg-pr-new Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@15870

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15870

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@15870

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@15870

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@15870

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@15870

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@15870

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@15870

miniflare

npm i https://pkg.pr.new/miniflare@15870

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15870

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@15870

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@15870

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@15870

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@15870

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@15870

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@15870

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@15870

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@15870

wrangler

npm i https://pkg.pr.new/wrangler@15870

commit: fe36d81

@NuroDev NuroDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners Bypass

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@dario-piotrowicz
dario-piotrowicz merged commit 8c4b8a3 into main Sep 25, 2026
64 checks passed
@dario-piotrowicz
dario-piotrowicz deleted the dario/packages-banner branch September 25, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants