Skip to content

Wrangler bundles code that imports WorkerEntrypoint as service worker if no default export is provided #15309

Description

@irvinebroque

What versions & operating system are you using?

MacOS Latest, Wrangler 4.125

Please provide a link to a minimal reproduction

https://github.com/irvinebroque/repro-esm-entrypoint

Describe the Bug

If you have code like this:

import { WorkerEntrypoint } from "cloudflare:workers";

// This is intentionally the only entrypoint. A named WorkerEntrypoint export is
// valid module-worker syntax and cannot run as a Service Worker.
export class NamedEntrypoint extends WorkerEntrypoint {
	fetch(): Response {
		return new Response("Hello from the named entrypoint");
	}
}
  • Wrangler incorrectly selects Service Worker format and fails.
  • The Vite plugin warns that default is missing, then adds an empty default export to the bundle.

So you have to do this if you are using Wrangler:

export default {
	fetch() {
		throw new Error("unimplemented");
	},
};

Please provide any relevant error logs

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    error-messagingImproving user facing error messagespackage:wranglerRelating to the `wrangler` package

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions