fix(vite): resolve project-specific tsconfig before workspace fallback (#31423)

## 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 <Coly010@users.noreply.github.com>
This commit is contained in:
Colum Ferry 2025-06-03 10:27:44 +01:00 committed by GitHub
parent 88c51965e6
commit b97ee099c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,12 +211,16 @@ 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) => {
]
.filter(Boolean)
.find((tsPath) => {
if (existsSync(tsPath)) {
logIt('Found tsconfig at', tsPath);
return tsPath;