Skip to content

Commit

Permalink
fix: exit dev if build fails on first run
Browse files Browse the repository at this point in the history
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
  • Loading branch information
threepointone committed Mar 31, 2022
1 parent 942e9f1 commit 8102d0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .changeset/itchy-cheetahs-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

fix: exit dev if build fails on first run

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.

Reported in https://github.com/cloudflare/wrangler2/issues/731
11 changes: 8 additions & 3 deletions packages/wrangler/src/dev/use-esbuild.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from "node:assert";
import { useApp } from "ink";
import { useState, useEffect } from "react";
import { bundleWorker } from "../bundle";
import type { Config } from "../config";
Expand Down Expand Up @@ -35,6 +36,7 @@ export function useEsbuild({
tsconfig: string | undefined;
}): EsbuildBundle | undefined {
const [bundle, setBundle] = useState<EsbuildBundle>();
const { exit } = useApp();
useEffect(() => {
let stopWatching: (() => void) | undefined = undefined;

Expand Down Expand Up @@ -82,9 +84,11 @@ export function useEsbuild({
});
}

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

return () => {
Expand All @@ -99,6 +103,7 @@ export function useEsbuild({
serveAssetsFromWorker,
rules,
tsconfig,
exit,
]);
return bundle;
}

0 comments on commit 8102d0b

Please sign in to comment.