privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.77k stars 154 forks source link

`ERR_UNSUPPORTED_ESM_URL_SCHEME` when running tsx watch on node 22.8.0 and 20.12.0 #650

Closed TheDogHusky closed 2 months ago

TheDogHusky commented 2 months ago

Acknowledgements

Minimal reproduction URL

https://github.com/NekoNyaDevs/bot

Problem & expected behavior (under 200 words)

So I'm updating a bot, and wanted to use tsx watch on development. I installed the package npm i tsx, made a script in package.json with cross-env NODE_ENV=development tsx watch src/index as content, on node 20.12.0. I ran the script, and got greeted by a painful error:

[15:52:01] [Nekonyan / Client] FATAL ▪ Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:228:11)
    at defaultLoad (node:internal/modules/esm/load:110:3)
    at nextLoad (node:internal/modules/esm/hooks:748:28)
    at load (file:///D:/Utilisateurs/Adam/Documents/dev/TypeScript/Bots/nekonyan/node_modules/tsx/dist/esm/index.mjs?1726062718911:2:1768)
    at nextLoad (node:internal/modules/esm/hooks:748:28)
    at Hooks.load (node:internal/modules/esm/hooks:385:26)
    at handleMessage (node:internal/modules/esm/worker:199:24)
    at Immediate.checkForMessages (node:internal/modules/esm/worker:141:28)
    at process.processImmediate (node:internal/timers:491:21)

I also tried on node 22.8.0, got the same issue. When I run tsc && node lib/index it works fine. So it must be a TSX issue (a guess, I could be wrong in my tsconfig too). I tried without the watch mode and still got an error.

Thank you in advance if you can help me out. I found that here had open a similar issue, that was outdated. And the solutions inside it didn't work. I don't use ESM, I'm on commonjs.

Bugs are expected to be fixed by those affected by it

Compensating engineering work will speed up resolution and support the project

privatenumber commented 2 months ago

Can you make your reproduction minimal? Happy to reopen once ready

TheDogHusky commented 2 months ago

As I have no ideas where the error comes from, I cannot tell which part of the whole repository causes the issue.

TheDogHusky commented 2 months ago

So making a minimal reproduction is pretty hard while including the cause of the error.

privatenumber commented 2 months ago

Hey @TheDogHusky,

This is a bug tracker, meant for reporting bugs with clear, reproducible steps and proof that the issue is with tsx. Without a minimal reproduction that isolates the problem, it's difficult to determine if the issue lies with tsx or with your specific setup.

If I debug without proof, the issue could end up being in your environment, and I'd essentially be offering free debugging support—which I don't have time for. However, if you can provide a minimal reproduction that clearly shows the issue is with tsx, I'd be happy to reopen the issue and investigate further.

Thanks for understanding!

U-4-E-A commented 1 month ago

I don't know if this will be of any help but I found the cause of this error with me was dead imports. This was happening in an import of an import of an import...

import { blah } from "@myAlias/thisDoesntActuallyExist"

U-4-E-A commented 1 month ago

Would it be possible for TSX to identify missing imports rather than give a slightly confusing error message?

privatenumber commented 1 month ago

Please don't comment on closed issues unless it's to re-open it (e.g. minimal repro provided).

You can file feature requests in the sponsor repo: https://github.com/pvtnbr/tsx