diff --git a/packages/nx/src/plugins/js/utils/register.ts b/packages/nx/src/plugins/js/utils/register.ts index 47bd4dfcd6512..f60d7bbde2bf1 100644 --- a/packages/nx/src/plugins/js/utils/register.ts +++ b/packages/nx/src/plugins/js/utils/register.ts @@ -1,6 +1,8 @@ import { dirname, join } from 'path'; import type { CompilerOptions } from 'typescript'; import { logger, NX_PREFIX, stripIndent } from '../../../utils/logger'; +import { existsSync } from 'fs'; +import { workspaceRoot } from '../../../utils/workspace-root'; const swcNodeInstalled = packageIsInstalled('@swc-node/register'); const tsNodeInstalled = packageIsInstalled('ts-node/register'); @@ -44,6 +46,11 @@ export function getSwcTranspiler( const register = require('@swc-node/register/register') .register as ISwcRegister; + let rootTsConfig = join(workspaceRoot, 'tsconfig.base.json'); + if (existsSync(rootTsConfig)) { + process.env.SWC_NODE_PROJECT = rootTsConfig; + } + const cleanupFn = register(compilerOptions); return typeof cleanupFn === 'function' ? cleanupFn : () => {};