fix(core): respect NX_PREFER_TS_NODE over native type stripping#35892
Merged
Conversation
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
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
01ae8d3 to
2a100fe
Compare
Contributor
|
View your CI Pipeline Execution ↗ for commit f43a776
☁️ Nx Cloud last updated this comment at |
FrozenPandaz
approved these changes
Jun 5, 2026
Contributor
There was a problem hiding this comment.
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.
🎓 Learn more about Self-Healing CI on nx.dev
…-Healing CI Rerun]
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
preferNodeStripTypesgate is evaluated at module load and short-circuits before the swc-vs-ts-node decision, whereNX_PREFER_TS_NODEis consulted. As a result, settingNX_PREFER_TS_NODE=truehas 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=truenow opts out of native type stripping, so the existing ts-node code path is used as intended. The opt-out is added to the authoritativepreferNodeStripTypesgate, keepingisNativeStripPreferred()andloadTsFilealigned. Behavior is unchanged when the flag is unset.Added
isNativeStripPreferredtest coverage across the runtime-support / env-flag combinations.Related Issue(s)
N/A