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

ESM – TypeError [ERR_UNKNOWN_FILE_EXTENSION] #72

Closed
tolu opened this issue Nov 27, 2020 · 9 comments
Closed

ESM – TypeError [ERR_UNKNOWN_FILE_EXTENSION] #72

tolu opened this issue Nov 27, 2020 · 9 comments

Comments

@tolu
Copy link

tolu commented Nov 27, 2020

I get this error when trying the typescript example with updated dependencies:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]:
    Unknown file extension ".ts" for /home/tolu/github/uvu/examples/typescript/tests/math.ts

An image for context πŸ˜„

image

Single tests files can be run via:

node --loader ts-node/esm test/math.ts
@cspotcode
Copy link

Did you mean to use our ESM loader? node --loader ts-node/esm

This is a node issue; the only way to hook into node's ESM loading is with node's --loader flag. If you have a way to specify --loader then you should be able to use ts-node's ESM loader to handle resolution and compilation of .ts files.

@tolu
Copy link
Author

tolu commented Nov 30, 2020

Oh, I did not know about ts-node/esm, thanks! πŸ™
but... I'm not specifically after using the ESM loader, I just want to get the typescript example in uvu working πŸ˜„ ESM or no-ESM.

That said, @cspotcode and I may be confusing things, but I thought that the dynamic import used by default here (uvu/run/index.mjs) WAS the ESM loader? And that since 0.5.0 this was enabled by default if hasImport in bin.js resolves to true?

So yes, I can run a single test-file at the time using node --loader ts-node/esm tests/math.ts, but how can I run the entire suite with uvu (not caring about ESM)?

@lukeed
Copy link
Owner

lukeed commented Nov 30, 2020

Hey, thanks!

What if the fix was to always use require/CommonJS mode if any -r/--require flag was defined?

As touched on here, ESM Node has --loader instead, and AFAIK cannot be hooked in outside of invoking node directly. And all require hooks need access to require.extensions (internal) in order to trigger X on loaded files.

@lukeed
Copy link
Owner

lukeed commented Nov 30, 2020

That said, we could still apply a form of the fix @tolu sent in #73 (thank you!) but that won't be the full story. For example, as of now, JSON modules.

I think the full fix is:

  1. uvu forcing CommonJS on -r/--require defined:
  2. handling ERR_UNKNOWN_FILE_EXTENSION error
    • this should not happen given (1) but is a nice fallback to have

@tolu
Copy link
Author

tolu commented Nov 30, 2020

@lukeed all that sounds great to me, I must admit that the finer (if not all) points of ESM-loading and the usage of node flags pass at some distance above my head, but I'd be glad to make the suggested changes to the PR πŸ‘

If not anything else I've certainly learned a lot trying to make sense of this πŸ˜„

@lukeed
Copy link
Owner

lukeed commented Nov 30, 2020

Cool. It's definitely in a weird-ish spot still. I'm working through it too (made clear here haha) Things definitely have progressed, but they definitely work better when it's all-or-nothing.

Just put the idea out there for now, to see if anyone can think of a reason why -r ~> CommonJS would be a terrible idea.
No need for changes at this time. I'll play with things & push any changes to your PR directly, if need be. Thanks!

@lukeed lukeed changed the title typescript example with updated dependencies throws: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" ESM – TypeError [ERR_UNKNOWN_FILE_EXTENSION] Dec 1, 2020
@lukeed
Copy link
Owner

lukeed commented Dec 1, 2020

OK. The first "half" of the fix is now available in 0.5.1

If you still experience this issue after upgrading, please leave some information here so that it can reproduced!
Hopefully it's been resolved fully, but my suspicion that we've not seen the end of it... yet

@tolu
Copy link
Author

tolu commented Dec 1, 2020

works like a charm πŸ™ πŸ™‡ thanks!

@lukeed
Copy link
Owner

lukeed commented Feb 24, 2021

Haven't had any issues at all with 0.5.1 (or heard of any).

I think we're good to go here. Can reopen in the future if something comes up.
Thanks!

@lukeed lukeed closed this as completed Feb 24, 2021
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 a pull request may close this issue.

3 participants