fix(core): do not load transpiler when within tsx environment #26723
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
If a user writes a custom script which wraps Nx (e.g. for
nx release
using our programmatic API) they may want to write it using TypeScript. If so,tsx
(https://tsx.is) is becoming a more and more popular choice for invoking such a script because it supports a ton of different file and module combinations with zero config.If a user invokes their script with
tsx
it is already priming node to be able to resolve TypeScript files and ESM files (and the combination of the two,.mts
files). Therefore if we perform our usual register logic in this case and further addswc
orts-node
into the mix, it causes conflicts in the node environment leading to hard to understand/troubleshoot errors such as:And
Expected Behavior
We detect when the current node process has been invoked via
tsx
and make our register logic a noop because everything in subsequent require/import calls should just work thanks totsx
.Related Issue(s)
Fixes #