diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 8cc2a95794..6efea3bb3c 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -63,7 +63,7 @@ async function initNuxt (nuxt: Nuxt) { nuxtCtx.set(nuxt) nuxt.hook('close', () => nuxtCtx.unset()) - const coreTypePackages = ['nitropack', 'defu', 'h3', '@unhead/vue', 'vue', 'vue-router', '@nuxt/schema'] + const coreTypePackages = nuxt.options.typescript.hoist || [] const paths = Object.fromEntries(await Promise.all(coreTypePackages.map(async (pkg) => { const path = await _resolvePath(pkg, { url: nuxt.options.modulesDir }).then(r => resolvePackageJSON(r)).catch(() => null) if (!path) { return } diff --git a/packages/schema/src/config/typescript.ts b/packages/schema/src/config/typescript.ts index 6cef2858b9..8c9eb2c2d0 100644 --- a/packages/schema/src/config/typescript.ts +++ b/packages/schema/src/config/typescript.ts @@ -26,6 +26,17 @@ export default defineUntypedSchema({ $resolve: val => val ?? null }, + /** + * Modules to generate deep aliases for within `compilerOptions.paths`. This does not yet support subpaths. + * It may be necessary when using Nuxt within a pnpm monorepo with `shamefully-hoist=false`. + */ + hoist: { + $resolve: (val) => { + const defaults = ['nitropack', 'defu', 'h3', '@unhead/vue', 'vue', 'vue-router', '@nuxt/schema'] + return val === false ? [] : (Array.isArray(val) ? val.concat(defaults) : defaults) + } + }, + /** * Include parent workspace in the Nuxt project. Mostly useful for themes and module authors. */