From 8102d0b4991e151937570f4b0918911492058d53 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Thu, 31 Mar 2022 09:22:47 +0530 Subject: [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 --- .changeset/itchy-cheetahs-sit.md | 9 +++++++++ packages/wrangler/src/dev/use-esbuild.ts | 11 ++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/itchy-cheetahs-sit.md diff --git a/.changeset/itchy-cheetahs-sit.md b/.changeset/itchy-cheetahs-sit.md new file mode 100644 index 000000000000..4ede38819d5b --- /dev/null +++ b/.changeset/itchy-cheetahs-sit.md @@ -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 diff --git a/packages/wrangler/src/dev/use-esbuild.ts b/packages/wrangler/src/dev/use-esbuild.ts index c219386bdb44..594efb46d964 100644 --- a/packages/wrangler/src/dev/use-esbuild.ts +++ b/packages/wrangler/src/dev/use-esbuild.ts @@ -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"; @@ -35,6 +36,7 @@ export function useEsbuild({ tsconfig: string | undefined; }): EsbuildBundle | undefined { const [bundle, setBundle] = useState(); + const { exit } = useApp(); useEffect(() => { let stopWatching: (() => void) | undefined = undefined; @@ -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 () => { @@ -99,6 +103,7 @@ export function useEsbuild({ serveAssetsFromWorker, rules, tsconfig, + exit, ]); return bundle; }