Skip to content

[wrangler] Support named-only module Workers in dev - #15611

Open
taylorlee wants to merge 2 commits into
mainfrom
tlee/no-default-export-local-dev
Open

taylorlee wants to merge 2 commits into
mainfrom
tlee/no-default-export-local-dev

Conversation

@taylorlee

@taylorlee taylorlee commented Sep 11, 2026

Copy link
Copy Markdown
Member

The middleware facade only wraps the default entrypoint and re-exports named entrypoints unchanged, so skipping it for named-only modules preserves existing behavior while avoiding an invalid default import.

The regression test waits for the Worker runtime to reload and fails on build errors because worker.ready only indicates that the proxy server started and can resolve after a recoverable bundling failure.

Followup to #15518


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: I have a docs pr drafted but wanted to fix any known issues in tooling here first. Docs will also only simplify the superfluous default exports for entrypoint examples, nothing needed to document for this to start working.

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


Devin Review

The middleware facade only wraps the default entrypoint and re-exports named entrypoints unchanged, so skipping it for named-only modules preserves existing behavior while avoiding an invalid default import.

The regression test waits for the Worker runtime to reload and fails on build errors because worker.ready only indicates that the proxy server started and can resolve after a recoverable bundling failure.
@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 226a196

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

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin 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 11, 2026
@workers-devprod
workers-devprod requested review from a team and petebacondarwin and removed request for a team September 11, 2026 17:41
@workers-devprod

workers-devprod commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/calm-counters-develop.md: [@cloudflare/wrangler]
  • packages/wrangler/e2e/multiworker-dev.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/middleware.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deployment-bundle/apply-middleware.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deployment-bundle/bundle.ts: [@cloudflare/wrangler]
  • packages/wrangler/templates/middleware/middleware-patch-console-prefix.ts: [@cloudflare/wrangler]

Comment thread packages/wrangler/src/deployment-bundle/apply-middleware.ts
@ask-bonk

ask-bonk Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

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

Adds named-only module Worker support in local development.

  1. P2: Named-only Workers lose multi-worker console prefixes. Posted one suggestion comment.

github run

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented Sep 11, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/build-output-utils

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

@cloudflare/codemods

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

@cloudflare/config

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

@cloudflare/containers-shared

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

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-plugin

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 226a196

Move console-prefix from request middleware to an esbuild inject.

The console-prefix module was previously loaded through the middleware
facade only for its import-time side effect. Its default export was a
passthrough that did not alter request handling.

This is a noop refactor for default exports because injecting the module
directly still applies the same patch.

This is a fix for named-only workers, which were never able to load the
middleware previously anyway.
@petebacondarwin

Copy link
Copy Markdown
Contributor

packages/wrangler/src/deployment-bundle/apply-middleware.ts:R32-38

Export changes break watched rebuilds

After a running Worker adds or removes its default export, entry.exports remains the startup snapshot during watched rebuilds. The stale value regenerates the invalid facade or skips required development middleware, so the edited Worker cannot reload correctly.

Wrangler computes entry.exports while resolving the entrypoint, before starting the esbuild watch context. Each source edit rebuilds through #startBundle with that same Entry; esbuild does not rerun the facade-selection code with updated exports. Removing the default export therefore leaves "default" in the snapshot and recreates the facade that this change intends to avoid. Adding a default export to a named-only Worker leaves the snapshot named-only and keeps request-body draining, scheduled testing, and local error middleware disabled.

Example: Start wrangler dev with export default { fetch() {} }, then replace it with export class Api extends WorkerEntrypoint {}. The watch rebuild still treats the module as having a default export and fails on the generated default import instead of loading Api.

Recommended fix: Derive facade eligibility from each build's current export metadata, or restart/reconfigure the bundle when the entrypoint's export shape changes. Add watch-mode tests for both default-to-named-only and named-only-to-default edits.


Allow `wrangler dev` to start module Workers without a default export

Wrangler now skips default-entrypoint middleware for Workers that only export named entrypoints. This avoids generating a middleware facade with an invalid default import.

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.

Changeset exposes internal implementation
The second paragraph discusses the middleware facade and generated imports. REVIEW.md requires changesets to describe user-facing impact instead of internal implementation.

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

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants