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

Error: tsx must be loaded with --import instead of --loader #3

Open
dangnhdev opened this issue Nov 15, 2023 · 4 comments
Open

Error: tsx must be loaded with --import instead of --loader #3

dangnhdev opened this issue Nov 15, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@dangnhdev
Copy link

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/node_modules/tsx/dist/esm/index.mjs:1:1956)
    at Hooks.addCustomLoader (node:internal/modules/esm/hooks:178:24)
    at Hooks.register (node:internal/modules/esm/hooks:144:16)
    at async initializeHooks (node:internal/modules/esm/utils:184:5)
    at async customizedModuleWorker (node:internal/modules/esm/worker:86:24)

Node.js v20.9.0

I've just tried this new plugin and got this error. The file run without error with old plugin.

@Lordfirespeed Lordfirespeed added the bug Something isn't working label Dec 10, 2023
@Lordfirespeed
Copy link
Owner

Lordfirespeed commented Dec 10, 2023

I think this is partially due to changes in Node.js and TSX rather than this plugin, but I should be able to implement a fix!

@Lordfirespeed
Copy link
Owner

Lordfirespeed commented Dec 10, 2023

After some investigation ...

  • --import is available in all versions of Node >=18.18.0
  • For versions of Node <18.18.0, --import is not available so --loader (which is an alias for --experimental-loader) must be used

So, to resolve this issue -

  • When Node version >=18.18.0, use --import over --require in all possible scenarios
    • check for compatability with ts-node
    • check for compatability with esno and tsx
  • When Node version <18.18.0, use --require in all possible scenarios

@nullice
Copy link

nullice commented Jan 21, 2024

Perhaps you can provide an option directly

@Lordfirespeed
Copy link
Owner

Perhaps you can provide an option directly

Yes, that's my intention. I haven't got round to it. Feel free to contribute :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants