Error handling bugfix: pass #1
This commit is contained in:
+23
-7
@@ -7,11 +7,12 @@ import grabClientHydrationScript from "./grab-client-hydration-script";
|
||||
import path from "path";
|
||||
import virtualFilesPlugin from "./plugins/virtual-files-plugin";
|
||||
import esbuildCTXArtifactTracker from "./plugins/esbuild-ctx-artifact-tracker";
|
||||
import { existsSync } from "fs";
|
||||
const { HYDRATION_DST_DIR, BUNX_HYDRATION_SRC_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE, } = grabDirNames();
|
||||
import { logBuildErrorsOnce, } from "../../utils/build-error-log";
|
||||
import { log } from "../../utils/log";
|
||||
const { HYDRATION_DST_DIR, BUNX_HYDRATION_SRC_DIR } = grabDirNames();
|
||||
export default async function allPagesESBuildContextBundler(params) {
|
||||
const _t0 = Date.now();
|
||||
try {
|
||||
const did_process_exit_because_of_bundler_error = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
||||
const pages = grabAllPages({ exclude_api: true });
|
||||
global.BUNEXT_PAGE_FILES = pages;
|
||||
const dev = isDevelopment();
|
||||
@@ -28,6 +29,9 @@ export default async function allPagesESBuildContextBundler(params) {
|
||||
entryToPage.set(entryFile, { ...page, tsx });
|
||||
}
|
||||
const entryPoints = [...entryToPage.keys()].map((e) => `hydration-virtual:${e}`);
|
||||
// This is a brand-new context: wipe the previous context's failure
|
||||
// history so the "2 failed starts => dispose" guard starts fresh.
|
||||
global.BUNEXT_MAIN_CTX_BUILD_STARTS = 0;
|
||||
global.BUNEXT_BUNDLER_CTX = await esbuild.context({
|
||||
entryPoints,
|
||||
outdir: HYDRATION_DST_DIR,
|
||||
@@ -64,14 +68,26 @@ export default async function allPagesESBuildContextBundler(params) {
|
||||
"react/jsx-dev-runtime",
|
||||
...(global.BUNEXT_CONFIG.page_compiler_excludes || []),
|
||||
],
|
||||
logLevel: did_process_exit_because_of_bundler_error
|
||||
? "silent"
|
||||
: undefined,
|
||||
// esbuild's own error logging prints per attempt; the
|
||||
// artifact-tracker plugin reports errors (deduped, once) itself.
|
||||
logLevel: "silent",
|
||||
});
|
||||
await global.BUNEXT_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
catch (error) {
|
||||
console.log(`ESBUILD Error =>`, error);
|
||||
global.BUNEXT_BUILD_FAILED = true;
|
||||
// When the build fails with esbuild errors, the artifact-tracker's
|
||||
// onEnd already reported them (deduped). "Build failed with N errors"
|
||||
// is that same failure rethrown by esbuild's API — re-logging it here
|
||||
// would double every incident.
|
||||
if (String(error?.message || "").startsWith("Build failed with")) {
|
||||
return;
|
||||
}
|
||||
logBuildErrorsOnce([
|
||||
{
|
||||
text: `ESBUILD Error => ${error?.message || String(error)}`,
|
||||
},
|
||||
], (line) => log.error(line));
|
||||
}
|
||||
}
|
||||
function forceExternalReact() {
|
||||
|
||||
Reference in New Issue
Block a user