nuxt / devtools

Unleash Nuxt Developer Experience
https://devtools.nuxt.com
MIT License
2.81k stars 154 forks source link

fix: override `tsx` dependency to known fixed version (broken on Node v18.19.0+) #606

Closed nmggithub closed 5 months ago

nmggithub commented 5 months ago

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.

nmggithub commented 5 months ago

@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.