1- import { type Tree , readJson } from '@nx/devkit' ;
2- import { addTsConfigPath } from '@nx/js' ;
1+ import { type Tree , readJson , updateJson } from '@nx/devkit' ;
32
43import type { NormalizedSchema } from './normalize-options' ;
54
@@ -8,14 +7,24 @@ import type { NormalizedSchema } from './normalize-options';
87 * when the path is not already added.
98 *
109 * It's required to follow Payload design pattern in `src/app` files.
10+ *
11+ * Also ensures `baseUrl` is set — required so that both webpack's
12+ * TsConfigPathsPlugin and get-tsconfig (used by tsx/Payload CLI) can resolve
13+ * the path correctly without a leading `./`.
1114 */
1215export function addPathAlias ( tree : Tree , options : NormalizedSchema ) : void {
1316 const tsConfig = readJson ( tree , 'tsconfig.base.json' ) ;
1417 if ( '@payload-config' in ( tsConfig ?. compilerOptions ?. paths ?? { } ) ) {
1518 return ;
1619 }
1720
18- addTsConfigPath ( tree , '@payload-config' , [
19- `${ options . directory } /src/payload.config.ts`
20- ] ) ;
21+ updateJson ( tree , 'tsconfig.base.json' , ( json ) => {
22+ json . compilerOptions ??= { } ;
23+ json . compilerOptions . baseUrl ??= '.' ;
24+ json . compilerOptions . paths ??= { } ;
25+ json . compilerOptions . paths [ '@payload-config' ] = [
26+ `${ options . directory } /src/payload.config.ts`
27+ ] ;
28+ return json ;
29+ } ) ;
2130}
0 commit comments