diff --git a/packages/js/src/utils/buildable-libs-utils.ts b/packages/js/src/utils/buildable-libs-utils.ts index 4fd36a9187..c2adc5b070 100644 --- a/packages/js/src/utils/buildable-libs-utils.ts +++ b/packages/js/src/utils/buildable-libs-utils.ts @@ -430,7 +430,8 @@ export function createTmpTsConfig( tsconfigPath: string, workspaceRoot: string, projectRoot: string, - dependencies: DependentBuildableProjectNode[] + dependencies: DependentBuildableProjectNode[], + useWorkspaceAsBaseUrl: boolean = false ) { const tmpTsConfigPath = join( workspaceRoot, @@ -445,6 +446,12 @@ export function createTmpTsConfig( dependencies ); process.on('exit', () => cleanupTmpTsConfigFile(tmpTsConfigPath)); + + if (useWorkspaceAsBaseUrl) { + parsedTSConfig.compilerOptions ??= {}; + parsedTSConfig.compilerOptions.baseUrl = workspaceRoot; + } + writeJsonFile(tmpTsConfigPath, parsedTSConfig); return join(tmpTsConfigPath); } diff --git a/packages/vite/plugins/nx-tsconfig-paths.plugin.ts b/packages/vite/plugins/nx-tsconfig-paths.plugin.ts index adb51b8f33..2bf2fe3a16 100644 --- a/packages/vite/plugins/nx-tsconfig-paths.plugin.ts +++ b/packages/vite/plugins/nx-tsconfig-paths.plugin.ts @@ -110,7 +110,8 @@ There should at least be a tsconfig.base.json or tsconfig.json in the root of th foundTsConfigPath, workspaceRoot, relative(workspaceRoot, projectRoot), - dependencies + dependencies, + true ); if (config.command === 'serve') {