Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): do not load transpiler when within tsx environment #26723

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

JamesHenry
Copy link
Collaborator

@JamesHenry JamesHenry commented Jun 27, 2024

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 add swc or ts-node into the mix, it causes conflicts in the node environment leading to hard to understand/troubleshoot errors such as:

[ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
    at fileURLToPath (node:internal/url:1461:11)
    at finalizeResolution (node:internal/modules/esm/resolve:266:42)
    at moduleResolve (node:internal/modules/esm/resolve:933:10)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at nextResolve (node:internal/modules/esm/hooks:866:28)
    at F (file:///Users/james/Repos/open-source/typescript-eslint/typescript-eslint/node_modules/tsx/dist/esm/index.mjs?1719486022657:2:3049)
    at nextResolve (node:internal/modules/esm/hooks:866:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:304:30)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:35)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38) {
  code: 'ERR_INVALID_URL_SCHEME'
}

And

TypeError: Cannot assign to read only property '.mjs' of object '[object Object]'
    at /Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/pirates/lib/index.js:101:44
    at Array.forEach (<anonymous>)
    at addHook (/Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/pirates/lib/index.js:95:8)
    at register (/Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/@swc-node/register/register.ts:135:17)
    at getSwcTranspiler (/Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/nx/src/plugins/js/utils/register.js:40:23)
    at /Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/nx/src/plugins/js/utils/register.js:119:22
    at registerTranspiler (/Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/nx/src/plugins/js/utils/register.js:143:12)
    at registerTsProject (/Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/nx/src/plugins/js/utils/register.js:15:9)
    at resolveChangelogRenderer (/Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/nx/src/command-line/release/utils/resolve-changelog-renderer.js:18:66)
    at ensureChangelogRenderersAreResolvable (/Users/james/Repos/open-source/angular-eslint/angular-eslint-alt/node_modules/nx/src/command-line/release/config/config.js:693:77)

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 to tsx.

Related Issue(s)

Fixes #

Copy link

vercel bot commented Jun 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Jun 27, 2024 11:56am

@JamesHenry JamesHenry marked this pull request as ready for review June 27, 2024 12:05
@JamesHenry JamesHenry requested a review from a team as a code owner June 27, 2024 12:05
@JamesHenry JamesHenry enabled auto-merge (squash) June 27, 2024 12:23
@JamesHenry JamesHenry merged commit dcaa086 into master Jun 27, 2024
6 checks passed
@JamesHenry JamesHenry deleted the tsx-register-fix branch June 27, 2024 20:47
Copy link

github-actions bot commented Jul 6, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants