Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions .changeset/fix-modules-watch-stub-no-bundle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"wrangler": patch
---

[wrangler] Fix `No such module "wrangler:modules-watch"` crash when running `wrangler pages dev` with `no_bundle = true`

When `bundle: false` (e.g. `"no_bundle": true` in `wrangler.json`, or `--no-bundle` flag), esbuild does not resolve imports inside injected files. Previously, `modules-watch-stub.js` was always injected whenever `watch: true`, regardless of the `bundle` option. This left `import "wrangler:modules-watch"` as an unresolved import in the output, causing a runtime crash in workerd: `Uncaught Error: No such module "wrangler:modules-watch"`.

The fix is to only inject `modules-watch-stub.js` when `bundle: true`. When `bundle: false`, file-system watching is already handled via chokidar, so the esbuild-internal watch stub is not needed.
Comment thread
Sertug17 marked this conversation as resolved.
Outdated

Fixes #14845.
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