Error handling bugfix in dev server

This commit is contained in:
2026-07-20 20:41:30 +01:00
parent 1d0ac4aa80
commit e3a0f5fbeb
16 changed files with 582 additions and 431 deletions
+42 -37
View File
@@ -48,41 +48,46 @@ export default async function pagesSSRBundler(params) {
writeFileSync(path.join(BUNX_TMP_DIR, "ssr-entrypoints.json"), JSON.stringify(entryPoints, null, 4));
}
catch (error) { }
await esbuild.build({
entryPoints,
outdir: BUNX_CWD_MODULE_CACHE_DIR,
bundle: true,
minify: !dev,
format: "esm",
target: "esnext",
platform: "node",
define: {
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production"),
},
entryNames: "[dir]/[hash]",
metafile: true,
plugins: [
tailwindEsbuildPlugin,
ssrVirtualFilesPlugin({
entryToPage,
}),
ssrCTXArtifactTracker({
entryToPage,
post_build_fn: params?.post_build_fn,
}),
],
jsx: "automatic",
external: [
"react",
"react-dom",
"react/jsx-runtime",
"react/jsx-dev-runtime",
"bun:*",
"sqlite-vec",
"better-sqlite3",
...(config.ssr_compiler_excludes || []),
],
splitting: true,
// logLevel: "silent",
});
try {
await esbuild.build({
entryPoints,
outdir: BUNX_CWD_MODULE_CACHE_DIR,
bundle: true,
minify: !dev,
format: "esm",
target: "esnext",
platform: "node",
define: {
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production"),
},
entryNames: "[dir]/[hash]",
metafile: true,
plugins: [
tailwindEsbuildPlugin,
ssrVirtualFilesPlugin({
entryToPage,
}),
ssrCTXArtifactTracker({
entryToPage,
post_build_fn: params?.post_build_fn,
}),
],
jsx: "automatic",
external: [
"react",
"react-dom",
"react/jsx-runtime",
"react/jsx-dev-runtime",
"bun:*",
"sqlite-vec",
"better-sqlite3",
...(config.ssr_compiler_excludes || []),
],
splitting: true,
});
}
catch (error) {
global.SSR_BUNDLER_CTX_DISPOSED = true;
log.error(`SSR Bundler Error: ${error}`);
}
}
@@ -56,7 +56,12 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
_.merge(global.BUNDLER_CTX_MAP[artifact.local_path], artifact);
}
}
post_build_fn?.({ artifacts });
try {
await post_build_fn?.({ artifacts });
}
catch (error) {
log.error(`Post-build Error: ${error}`);
}
}
const elapsed = (performance.now() - build_start).toFixed(0);
log.success(`[Built] in ${elapsed}ms`);
@@ -82,7 +87,7 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
}
else {
try {
pagesSSRBundler();
await pagesSSRBundler();
}
catch (error) {
log.error(`SSR Bundler Error: ${error}`);
+8 -2
View File
@@ -23,9 +23,15 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
build.onEnd(async (result) => {
if (result.errors.length > 0) {
global.SSR_BUNDLER_CTX_DISPOSED = true;
await global.SSR_BUNDLER_CTX?.dispose();
try {
await global.SSR_BUNDLER_CTX?.dispose();
}
catch { }
global.SSR_BUNDLER_CTX = undefined;
build_starts = 0;
console.log("SSR Build errors:", result.errors);
for (const err of result.errors) {
console.error(`SSR Build error: ${err.text}${err.location ? ` (${err.location.file}:${err.location.line}:${err.location.column})` : ""}`);
}
return;
}
const artifacts = grabArtifactsFromBundledResults({