Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-modules-watch-stub-no-bundle.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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, {
Expand All @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/deployment-bundle/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading