From f6ecf9a202ee0a59ea99c8c5c1798766b17d4ced Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 19 Sep 2024 13:18:28 +0100 Subject: [PATCH] fix(nuxt): don't resolve relative import type paths for deps (#29069) --- packages/nuxt/src/core/nuxt.ts | 4 ++-- packages/nuxt/src/imports/module.ts | 5 ++++- packages/schema/src/types/nuxt.ts | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index a2b9c894da..18479a6fa7 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -179,13 +179,13 @@ async function initNuxt (nuxt: Nuxt) { const coreTypePackages = nuxt.options.typescript.hoist || [] const packageJSON = await readPackageJSON(nuxt.options.rootDir).catch(() => ({}) as PackageJson) - const dependencies = new Set([...Object.keys(packageJSON.dependencies || {}), ...Object.keys(packageJSON.devDependencies || {})]) + nuxt._dependencies = new Set([...Object.keys(packageJSON.dependencies || {}), ...Object.keys(packageJSON.devDependencies || {})]) const paths = Object.fromEntries(await Promise.all(coreTypePackages.map(async (pkg) => { const [_pkg = pkg, _subpath] = /^[^@]+\//.test(pkg) ? pkg.split('/') : [pkg] const subpath = _subpath ? '/' + _subpath : '' // ignore packages that exist in `package.json` as these can be resolved by TypeScript - if (dependencies.has(_pkg) && !(_pkg in nightlies)) { return [] } + if (nuxt._dependencies?.has(_pkg) && !(_pkg in nightlies)) { return [] } // deduplicate types for nightly releases if (_pkg in nightlies) { diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index acf7d5f87e..af728fb6db 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -166,8 +166,9 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial i.from))) + // skip relative import paths for node_modules that are explicitly installed await Promise.all(importSource.map(async (from) => { - if (resolvedImportPathMap.has(from)) { + if (resolvedImportPathMap.has(from) || nuxt._dependencies?.has(from)) { return } let path = resolveAlias(from) @@ -176,6 +177,8 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial /** The resolved Nuxt configuration. */ options: NuxtOptions