From 63bfaac120c0bc51190b1c1b3abe9fd6af660767 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 9 Mar 2024 06:07:39 +0000 Subject: [PATCH] fix(nuxt): handle errors resolving package paths --- packages/nuxt/src/core/nuxt.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 7195fc9575c6..a0746c002226 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -2,6 +2,7 @@ import { dirname, join, normalize, relative, resolve } from 'pathe' import { createDebugger, createHooks } from 'hookable' import type { LoadNuxtOptions } from '@nuxt/kit' import { addBuildPlugin, addComponent, addPlugin, addRouteMiddleware, addVitePlugin, addWebpackPlugin, installModule, loadNuxtConfig, logger, nuxtCtx, resolveAlias, resolveFiles, resolvePath, tryResolveModule, useNitro } from '@nuxt/kit' +import { resolvePath as _resolvePath } from 'mlly' import type { Nuxt, NuxtHooks, NuxtOptions } from 'nuxt/schema' import { resolvePackageJSON } from 'pkg-types' @@ -64,9 +65,10 @@ async function initNuxt (nuxt: Nuxt) { const coreTypePackages = ['nitropack', 'defu', 'h3', '@unhead/vue', 'vue', 'vue-router', '@nuxt/schema'] const paths = Object.fromEntries(await Promise.all(coreTypePackages.map(async pkg => { - const path = await resolvePath(pkg).then(r => resolvePackageJSON(r)) + const path = await _resolvePath(pkg, { url: nuxt.options.modulesDir }).then(r => resolvePackageJSON(r)).catch(() => null) + if (!path) { return } return [pkg, [dirname(path)]] - }))) + })).then((r) => r.filter(Boolean) as [string, [string]][])) // Set nitro resolutions for types that might be obscured with shamefully-hoist=false nuxt.options.nitro.typescript = defu(nuxt.options.nitro.typescript, {