Skip to content

Commit

Permalink
fix(nuxt): handle errors resolving package paths
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 9, 2024
1 parent e1b3c5e commit 63bfaac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/nuxt/src/core/nuxt.ts
Expand Up @@ -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'

Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 63bfaac

Please sign in to comment.