Skip to content

Commit abfc14d

Browse files
Guard createWebpackBuildPromise against early runWebpack rejection
Attach a catch handler to the async runWebpack call so early setup errors (e.g., failing dynamic imports) properly reject the outer promise instead of hanging. Mirrored the same protection in the development single-build path to surface failures deterministically. This prevents silent timeouts during CI and improves failure signaling without altering build outputs.
1 parent 1406522 commit abfc14d

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

build.mjs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -544,21 +544,29 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
544544
async function build() {
545545
await deleteOldDir()
546546
function createWebpackBuildPromise(isWithoutKatex, isWithoutTiktoken, minimal, tmpDir, suffix) {
547-
return new Promise((resolve, reject) =>
548-
runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, tmpDir, async (err, stats) => {
549-
if (err || (stats && typeof stats.hasErrors === 'function' && stats.hasErrors())) {
550-
console.error(err || stats.toString())
551-
reject(err || new Error('webpack error'))
552-
return
553-
}
554-
try {
555-
await finishOutput(suffix, tmpDir)
556-
resolve()
557-
} catch (copyErr) {
558-
reject(copyErr)
559-
}
560-
}),
561-
)
547+
return new Promise((resolve, reject) => {
548+
const ret = runWebpack(
549+
isWithoutKatex,
550+
isWithoutTiktoken,
551+
minimal,
552+
tmpDir,
553+
async (err, stats) => {
554+
if (err || (stats && typeof stats.hasErrors === 'function' && stats.hasErrors())) {
555+
console.error(err || stats.toString())
556+
reject(err || new Error('webpack error'))
557+
return
558+
}
559+
try {
560+
await finishOutput(suffix, tmpDir)
561+
resolve()
562+
} catch (copyErr) {
563+
reject(copyErr)
564+
}
565+
},
566+
)
567+
// runWebpack is async; catch early rejections (e.g., failed dynamic imports)
568+
if (ret && typeof ret.then === 'function') ret.catch(reject)
569+
})
562570
}
563571
if (isProduction && !isAnalyzing) {
564572
const tmpFull = `${outdir}/.tmp-full`
@@ -580,8 +588,8 @@ async function build() {
580588
return
581589
}
582590

583-
await new Promise((resolve, reject) =>
584-
runWebpack(false, false, false, outdir, async (err, stats) => {
591+
await new Promise((resolve, reject) => {
592+
const ret = runWebpack(false, false, false, outdir, async (err, stats) => {
585593
if (err || (stats && typeof stats.hasErrors === 'function' && stats.hasErrors())) {
586594
console.error(err || stats.toString())
587595
reject(err || new Error('webpack error'))
@@ -593,8 +601,9 @@ async function build() {
593601
} catch (e) {
594602
reject(e)
595603
}
596-
}),
597-
)
604+
})
605+
if (ret && typeof ret.then === 'function') ret.catch(reject)
606+
})
598607
}
599608

600609
build().catch((e) => {

0 commit comments

Comments
 (0)