diff --git a/.changeset/fix-modules-watch-stub-no-bundle.md b/.changeset/fix-modules-watch-stub-no-bundle.md new file mode 100644 index 00000000000..267787242d4 --- /dev/null +++ b/.changeset/fix-modules-watch-stub-no-bundle.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +Fix `wrangler dev` commands crashing with `No such module "wrangler:modules-watch"` when `"no_bundle": true` + +Running `wrangler dev` or `wrangler pages dev` with bundling disabled (`"no_bundle": true` in `wrangler.json`, or the `--no-bundle` flag) no longer crashes at startup with `Uncaught Error: No such module "wrangler:modules-watch"`. Live reloading on file changes continues to work as before. diff --git a/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts b/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts index 695194008b0..95d37bd9b59 100644 --- a/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts +++ b/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts @@ -87,7 +87,13 @@ describe("BundleController", { retry: 5, timeout: 10_000 }, () => { afterEach(() => controller.teardown()); describe("happy path bundle + watch", () => { - test("single ts source file", async ({ expect }) => { + test.for([ + { name: "bundled", build: {} }, + { + name: "unbundled with entrypoint processing", + build: { bundle: false, processEntrypoint: true }, + }, + ])("single ts source file ($name)", async ({ build }, { expect }) => { await seed({ "src/index.ts": dedent /* javascript */ ` export default { @@ -101,11 +107,17 @@ describe("BundleController", { retry: 5, timeout: 10_000 }, () => { const config = configDefaults({ entrypoint: path.resolve("src/index.ts"), projectRoot: path.resolve("src"), + build, }); const ev = bus.waitFor("bundleComplete"); controller.onConfigUpdate({ type: "configUpdate", config }); - expect(findSourceFile((await ev).bundle.entrypointSource, "index.ts")) - .toMatchInlineSnapshot(` + const initialSource = (await ev).bundle.entrypointSource; + expect(initialSource).not.toContain("wrangler:modules-watch"); + if (build.bundle === false) { + return; + } + expect(initialSource).toContain("hello world"); + expect(findSourceFile(initialSource, "index.ts")).toMatchInlineSnapshot(` "// index.ts var index_exports = {}; __export(index_exports, { @@ -131,8 +143,10 @@ describe("BundleController", { retry: 5, timeout: 10_000 }, () => { } satisfies ExportedHandler `, }); - expect(findSourceFile((await ev2).bundle.entrypointSource, "index.ts")) - .toMatchInlineSnapshot(` + const updatedSource = (await ev2).bundle.entrypointSource; + expect(updatedSource).not.toContain("wrangler:modules-watch"); + expect(updatedSource).toContain("hello world 2"); + expect(findSourceFile(updatedSource, "index.ts")).toMatchInlineSnapshot(` "// index.ts var index_exports = {}; __export(index_exports, { diff --git a/packages/wrangler/src/deployment-bundle/bundle.ts b/packages/wrangler/src/deployment-bundle/bundle.ts index ee99209fa73..bdbbfce05c0 100644 --- a/packages/wrangler/src/deployment-bundle/bundle.ts +++ b/packages/wrangler/src/deployment-bundle/bundle.ts @@ -317,7 +317,7 @@ export async function bundleWorker( inject.push(...(result.inject ?? [])); } - if (watch) { + if (watch && bundle) { // `esbuild` doesn't support returning `watch*` options from `onStart()` // plugin callbacks. Instead, we define an empty virtual module that is // imported in this injected module. Importing that module registers watchers.