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: override tsx dependency to known fixed version (broken on Node v18.19.0+) #606

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

nmggithub
Copy link
Contributor

@nmggithub nmggithub commented Feb 27, 2024

Issue

Attempting to follow the Contribution Guide and run:

pnpm i
pnpm run build

on a new clone of the project on Node v18.19.0+ will result in the following error message (after some logs):

 node:internal/process/esm_loader:40
       internalBinding('errors').triggerUncaughtException(
                                 ^
 Error: tsx must be loaded with --import instead of --loader
 The --loader flag was deprecated in Node v20.6.0
     at V (file://{project root}/node_modules/.pnpm/tsx@4.1.1/node_modules/tsx/dist/esm/index.mjs:1:1956)
     at Hooks.addCustomLoader (node:internal/modules/esm/hooks:202:24)
     at Hooks.register (node:internal/modules/esm/hooks:168:16)
     at async initializeHooks (node:internal/modules/esm/utils:167:5)
     at async customizedModuleWorker (node:internal/modules/esm/worker:104:24)

Research

Looking into this:

  1. I came across this issue showing the same issue in Backstage,
  2. in which I saw this comment from one of their maintainers, GitHub user @freben (thanks, Fredrik!),
  3. which linked to this section of the Node.js changelog, which seems to confirm this is an issue with Node v18.19.0+.
  4. I then looked at the tsx GitHub issues and found this issue mentioning the same changelog,
  5. in which I found this comment from the owner, @privatenumber (thanks, Hiroki!), saying the issue is fixed in v4.6.1 of tsx.

The cause (error trace)

This tsx issue is indeed the cause in this repo.

  1. pnpm run build runs pnpm -r --filter=\"./packages/**/*\" run build, which runs the build scripts in all packages in packages/**/*
  2. the build script in packages/devtools includes esno scripts/prepare.ts
  3. the package esno is a thin wrapper around tsx,
  4. esno includes tsx in its package.json, but as ^4.1.0, which can (and does) resolve to versions earlier than the fixed v4.6.1

The solution

This PR simply adds a PNPM override of ^v4.6.1 for the tsx package.

Additional comments

It would be nice if the authors of esno fixed the issue in their package.json, but they don't seem to be open to this as they have disabled issues on the esno repo and have told people to open issues in the tsx repo instead.

@antfu antfu merged commit 1bc2e71 into nuxt:main Feb 27, 2024
2 checks passed
@nmggithub
Copy link
Contributor Author

@antfu I noticed the earlier discussion in the Discord where this error appeared in CI. I believe your fix then was to pin the Node version in CI to 18.18.2. While not too important, I think this could go up to 18.19.x now that this fix has been merged in.

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.

None yet

2 participants