From e109d81d40829f99ce5cc9984308db9cd700c9fb Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 7 Jun 2024 10:56:48 +0100 Subject: [PATCH] fix(nuxt): handle errors loading app manifest (#27441) --- packages/nuxt/src/app/composables/manifest.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/app/composables/manifest.ts b/packages/nuxt/src/app/composables/manifest.ts index 58b53745c9..c828faeeb3 100644 --- a/packages/nuxt/src/app/composables/manifest.ts +++ b/packages/nuxt/src/app/composables/manifest.ts @@ -24,9 +24,13 @@ function fetchManifest () { if (!isAppManifestEnabled) { throw new Error('[nuxt] app manifest should be enabled with `experimental.appManifest`') } - manifest = $fetch(buildAssetsURL(`builds/meta/${useRuntimeConfig().app.buildId}.json`)) + manifest = $fetch(buildAssetsURL(`builds/meta/${useRuntimeConfig().app.buildId}.json`), { + responseType: 'json', + }) manifest.then((m) => { matcher = createMatcherFromExport(m.matcher) + }).catch((e) => { + console.error('[nuxt] Error fetching app manifest.', e) }) return manifest } @@ -48,5 +52,14 @@ export async function getRouteRules (url: string) { return defu({} as Record, ..._routeRulesMatcher.matchAll(url).reverse()) } await getAppManifest() - return defu({} as Record, ...matcher.matchAll(url).reverse()) + if (!matcher) { + console.error('[nuxt] Error creating app manifest matcher.', matcher) + return {} + } + try { + return defu({} as Record, ...matcher.matchAll(url).reverse()) + } catch (e) { + console.error('[nuxt] Error matching route rules.', e) + return {} + } }