Skip to content

Commit a1dadac

Browse files
fix: exit dev if build fails on first run (#734)
Because of evanw/esbuild#1037, we can't recover dev if esbuild fails on first run. The workaround is to end the process if it does so, until we have a better fix. Reported in #731
1 parent 942e9f1 commit a1dadac

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.changeset/itchy-cheetahs-sit.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: exit dev if build fails on first run
6+
7+
Because of https://github.com/evanw/esbuild/issues/1037, we can't recover dev if esbuild fails on first run. The workaround is to end the process if it does so, until we have a better fix.
8+
9+
Reported in https://github.com/cloudflare/wrangler2/issues/731

packages/wrangler/src/dev/use-esbuild.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from "node:assert";
2+
import { useApp } from "ink";
23
import { useState, useEffect } from "react";
34
import { bundleWorker } from "../bundle";
45
import type { Config } from "../config";
@@ -35,6 +36,7 @@ export function useEsbuild({
3536
tsconfig: string | undefined;
3637
}): EsbuildBundle | undefined {
3738
const [bundle, setBundle] = useState<EsbuildBundle>();
39+
const { exit } = useApp();
3840
useEffect(() => {
3941
let stopWatching: (() => void) | undefined = undefined;
4042

@@ -82,9 +84,11 @@ export function useEsbuild({
8284
});
8385
}
8486

85-
build().catch(() => {
86-
// esbuild already logs errors to stderr and we don't want to end the process
87-
// on build errors anyway so this is a no-op error handler
87+
build().catch((err) => {
88+
// If esbuild fails on first run, we want to quit the process
89+
// since we can't recover from here
90+
// related: https://github.com/evanw/esbuild/issues/1037
91+
exit(err);
8892
});
8993

9094
return () => {
@@ -99,6 +103,7 @@ export function useEsbuild({
99103
serveAssetsFromWorker,
100104
rules,
101105
tsconfig,
106+
exit,
102107
]);
103108
return bundle;
104109
}

0 commit comments

Comments
 (0)