Skip to content

fix(core): respect NX_PREFER_TS_NODE over native type stripping#35892

Merged
FrozenPandaz merged 2 commits into
masterfrom
fix-ts-node-strip-types
Jun 5, 2026
Merged

fix(core): respect NX_PREFER_TS_NODE over native type stripping#35892
FrozenPandaz merged 2 commits into
masterfrom
fix-ts-node-strip-types

Conversation

@AgentEnder

Copy link
Copy Markdown
Member

Current Behavior

When the Node.js runtime supports native TypeScript type stripping (Node 22.18+ LTS, 23.6+, or 22.6–22.17 with --experimental-strip-types), Nx defers to native stripping and skips registering a transpiler entirely.

The preferNodeStripTypes gate is evaluated at module load and short-circuits before the swc-vs-ts-node decision, where NX_PREFER_TS_NODE is consulted. As a result, setting NX_PREFER_TS_NODE=true has no effect on modern Node — native stripping wins, even though the user explicitly asked for ts-node. This is a problem for workspaces using constructs native stripping can't handle the way ts-node would (e.g. relying on full type-aware transpilation rather than stripping).

Expected Behavior

Setting NX_PREFER_TS_NODE=true now opts out of native type stripping, so the existing ts-node code path is used as intended. The opt-out is added to the authoritative preferNodeStripTypes gate, keeping isNativeStripPreferred() and loadTsFile aligned. Behavior is unchanged when the flag is unset.

Added isNativeStripPreferred test coverage across the runtime-support / env-flag combinations.

Related Issue(s)

N/A

@AgentEnder AgentEnder requested a review from a team as a code owner June 5, 2026 18:13
@AgentEnder AgentEnder requested a review from FrozenPandaz June 5, 2026 18:13
@netlify

netlify Bot commented Jun 5, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit f43a776
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a23222c1a4c3a000857603b
😎 Deploy Preview https://deploy-preview-35892--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 5, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit f43a776
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a23222cfcb63e0008f7c033
😎 Deploy Preview https://deploy-preview-35892--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

- Opt out of Node's native TypeScript stripping when NX_PREFER_TS_NODE=true,
  since that flag explicitly requests ts-node for transpilation
- Previously the native-strip gate short-circuited before the swc/ts-node
  decision, so NX_PREFER_TS_NODE had no effect on modern Node runtimes
- Add isNativeStripPreferred test coverage across the env/runtime combinations
@AgentEnder AgentEnder force-pushed the fix-ts-node-strip-types branch from 01ae8d3 to 2a100fe Compare June 5, 2026 18:30
@nx-cloud

nx-cloud Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit f43a776

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 50m 42s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 1m 2s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 18s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-05 20:18:45 UTC

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud has identified a flaky task in your failed CI:

🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.

Nx Cloud View detailed reasoning in Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

@FrozenPandaz FrozenPandaz merged commit 7601aaa into master Jun 5, 2026
25 checks passed
@FrozenPandaz FrozenPandaz deleted the fix-ts-node-strip-types branch June 5, 2026 20:40
vrxj81 pushed a commit to vrxj81/nx that referenced this pull request Jun 7, 2026
…#35892)

## Current Behavior

When the Node.js runtime supports native TypeScript type stripping (Node
22.18+ LTS, 23.6+, or 22.6–22.17 with `--experimental-strip-types`), Nx
defers to native stripping and skips registering a transpiler entirely.

The `preferNodeStripTypes` gate is evaluated at module load and
short-circuits *before* the swc-vs-ts-node decision, where
`NX_PREFER_TS_NODE` is consulted. As a result, setting
`NX_PREFER_TS_NODE=true` has **no effect** on modern Node — native
stripping wins, even though the user explicitly asked for ts-node. This
is a problem for workspaces using constructs native stripping can't
handle the way ts-node would (e.g. relying on full type-aware
transpilation rather than stripping).

## Expected Behavior

Setting `NX_PREFER_TS_NODE=true` now opts out of native type stripping,
so the existing ts-node code path is used as intended. The opt-out is
added to the authoritative `preferNodeStripTypes` gate, keeping
`isNativeStripPreferred()` and `loadTsFile` aligned. Behavior is
unchanged when the flag is unset.

Added `isNativeStripPreferred` test coverage across the runtime-support
/ env-flag combinations.

## Related Issue(s)

N/A

---------

Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants