diff --git a/docs/shared/reference/environment-variables.md b/docs/shared/reference/environment-variables.md index 91f050cf42bdd..2bac4696d7ede 100644 --- a/docs/shared/reference/environment-variables.md +++ b/docs/shared/reference/environment-variables.md @@ -21,6 +21,7 @@ The following environment variables are ones that you can set to change the beha | NX_DRY_RUN | boolean | If set to `true`, will perform a dry run of the generator. No files will be created and no packages will be installed. | | NX_INTERACTIVE | boolean | If set to `true`, will allow Nx to prompt you in the terminal to answer some further questions when running generators. | | NX_GENERATE_QUIET | boolean | If set to `true`, will prevent Nx logging file operations during generate | +| NX_PREFER_TS_NODE | boolean | If set to `true`, Nx will use ts-node for local execution of plugins even if `@swc-node/register` is installed. | Nx will set the following environment variables so they can be accessible within the process even outside of executors and generators diff --git a/packages/nx/src/utils/register.ts b/packages/nx/src/utils/register.ts index de87ed3f8ce3b..b0b39089f50f2 100644 --- a/packages/nx/src/utils/register.ts +++ b/packages/nx/src/utils/register.ts @@ -49,14 +49,16 @@ export function registerTranspiler( // Function to register transpiler that returns cleanup function let registerTranspiler: () => () => void; - if (swcNodeInstalled) { + const preferTsNode = process.env.NX_PREFER_TS_NODE === 'true'; + + if (swcNodeInstalled && !preferTsNode) { // These are requires to prevent it from registering when it shouldn't const { register } = require('@swc-node/register/register') as typeof import('@swc-node/register/register'); registerTranspiler = () => register(compilerOptions); } else { - // We can fall back on ts-node if its available + // We can fall back on ts-node if it's available if (tsNodeInstalled) { const { register } = require('ts-node') as typeof import('ts-node');