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
5 changes: 5 additions & 0 deletions .changeset/fix-unhandled-rejection-esbuild-entry-deleted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fix unhandled promise rejection when the worker entry point is deleted or moved during `wrangler dev` hot-reload — now logs a warning and skips the update instead of crashing
21 changes: 16 additions & 5 deletions packages/wrangler/src/dev/use-esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getWrangler1xLegacyModuleReferences,
noopModuleCollector,
} from "../deployment-bundle/module-collection";
import { logger } from "../logger";
import type { SourceMapMetadata } from "../deployment-bundle/bundle";
import type { Entry } from "../deployment-bundle/entry";
import type { CfModule, CfModuleType, Config } from "@cloudflare/workers-utils";
Expand Down Expand Up @@ -131,13 +132,23 @@ export function runBuild(
previousBundle,
"Rebuild triggered with no previous build available"
);
previousBundle.modules = dedupeModulesByName([
...(moduleCollector?.modules ?? []),
...newAdditionalModules,
]);
let entrypointSource: string;
try {
entrypointSource = readFileSync(previousBundle.path, "utf8");
} catch (e) {
// Entry point was deleted or moved between builds — skip this update.
logger.warn(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid concern. logger.once does not exist in this codebase. Repeated warnings will surface the issue to the developer without crashing the session. A deduplication helper can be added as a follow-up if the spam proves problematic in practice.

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.

logger.once.warn() does exist in this codebase, might be a good option here

`Could not read entrypoint "${previousBundle.path}": ${(e as NodeJS.ErrnoException).message}`
Comment thread
penalosa marked this conversation as resolved.
);
return previousBundle;
}
Comment thread
matingathani marked this conversation as resolved.
return {
...previousBundle,
entrypointSource: readFileSync(previousBundle.path, "utf8"),
modules: dedupeModulesByName([
...(moduleCollector?.modules ?? []),
...newAdditionalModules,
]),
entrypointSource,
id: previousBundle.id + 1,
};
});
Expand Down
Loading