Skip to content

Commit 34d7be7

Browse files
committed
fix: improved debugging when bundling fails
Fixes #328
1 parent 864102f commit 34d7be7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/plugins/transform.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async function downloadScript(opts: {
103103
let size = 0
104104
res = await $fetch.raw(src, { ...fetchOptions, responseType: 'arrayBuffer' }).then(async (r) => {
105105
if (!r.ok) {
106-
throw new Error(`Failed to fetch ${src}`)
106+
throw new Error(`Failed to fetch ${src} (HTTP ${r.status})`)
107107
}
108108
encoding = r.headers.get('content-encoding')
109109
const contentLength = r.headers.get('content-length')
@@ -140,6 +140,9 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
140140
// done after all transformation is done
141141
// copy all scripts to build
142142
nuxt.hooks.hook('build:done', async () => {
143+
if (nuxt.options._prepare) {
144+
return
145+
}
143146
const scripts = [...renderedScript]
144147
if (!scripts.length) {
145148
logger.debug('[bundle-script-transformer] No scripts to bundle...')
@@ -334,12 +337,18 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
334337
try {
335338
await downloadScript({ src, url, filename, forceDownload }, renderedScript, options.fetchOptions, options.cacheMaxAge)
336339
}
337-
catch (e) {
340+
catch (e: any) {
338341
if (options.fallbackOnSrcOnBundleFail) {
339342
logger.warn(`[Nuxt Scripts: Bundle Transformer] Failed to bundle ${src}. Fallback to remote loading.`)
340343
url = src
341344
}
342345
else {
346+
// Provide more helpful error message, especially for Docker/network issues
347+
const errorMessage = e?.message || 'Unknown error'
348+
if (errorMessage.includes('timeout') || errorMessage.includes('network') || errorMessage.includes('ENOTFOUND')) {
349+
logger.error(`[Nuxt Scripts: Bundle Transformer] Network issue while bundling ${src}: ${errorMessage}`)
350+
logger.error(`[Nuxt Scripts: Bundle Transformer] Tip: Set 'fallbackOnSrcOnBundleFail: true' in module options or disable bundling in Docker environments`)
351+
}
343352
throw e
344353
}
345354
}

0 commit comments

Comments
 (0)