From b97ee099c893f7c3aa79e11fe1136d7420fe2b1e Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Tue, 3 Jun 2025 10:27:44 +0100 Subject: [PATCH] fix(vite): resolve project-specific tsconfig before workspace fallback (#31423) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Current Behavior The Nx Vite TsConfig paths plugin incorrectly resolves to workspace root tsconfig files instead of project-specific ones, causing path aliases like `@/contexts` to fail resolution. ## Expected Behavior The plugin should check for project-specific tsconfig files (`tsconfig.app.json`, `tsconfig.lib.json`, `tsconfig.json`) before falling back to workspace root configurations. ## Related Issue(s) Fixes #28945 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Coly010 --- .../vite/plugins/nx-tsconfig-paths.plugin.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/vite/plugins/nx-tsconfig-paths.plugin.ts b/packages/vite/plugins/nx-tsconfig-paths.plugin.ts index 8574b274c5..551770642e 100644 --- a/packages/vite/plugins/nx-tsconfig-paths.plugin.ts +++ b/packages/vite/plugins/nx-tsconfig-paths.plugin.ts @@ -20,6 +20,7 @@ import { Plugin } from 'vite'; import { nxViteBuildCoordinationPlugin } from './nx-vite-build-coordination.plugin'; import { findFile } from '../src/utils/nx-tsconfig-paths-find-file'; import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup'; +import { getProjectTsConfigPath } from '../src/utils/options-utils'; export interface nxViteTsPathsOptions { /** @@ -210,17 +211,21 @@ export function nxViteTsPaths(options: nxViteTsPathsOptions = {}) { } as Plugin; function getTsConfig(preferredTsConfigPath: string): string { + const projectTsConfigPath = getProjectTsConfigPath(projectRoot); return [ resolve(preferredTsConfigPath), + projectTsConfigPath ? resolve(projectTsConfigPath) : null, resolve(join(workspaceRoot, 'tsconfig.base.json')), resolve(join(workspaceRoot, 'tsconfig.json')), resolve(join(workspaceRoot, 'jsconfig.json')), - ].find((tsPath) => { - if (existsSync(tsPath)) { - logIt('Found tsconfig at', tsPath); - return tsPath; - } - }); + ] + .filter(Boolean) + .find((tsPath) => { + if (existsSync(tsPath)) { + logIt('Found tsconfig at', tsPath); + return tsPath; + } + }); } function logIt(...msg: any[]) {