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

uvu with svelte #122

Closed
jerrythomas opened this issue Jun 29, 2021 · 3 comments
Closed

uvu with svelte #122

jerrythomas opened this issue Jun 29, 2021 · 3 comments

Comments

@jerrythomas
Copy link

Uvu makes it painless to test ESM modules without the -r esm.
However, the svelte example still suggests using -r esm and -r tests/setup/register.js.

Whe I try to use it I get the error below

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
require() of ES modules is not supported.

Is there a way that svelte testing can be done without the require?

@lukeed
Copy link
Owner

lukeed commented Jun 29, 2021

Thanks

Is there a way that svelte testing can be done without the require?

No because the *.svelte files need a --require hook in order to be compiled. And any use of --require automatically moves uvu into CJS mode.

The ESM --loader hook API is still experimental, but exists. I don't recommend experimental APIs so there's no example of it, but you're welcome to try & piece it together yourself :) Circle back with a TLDR if you decide to go this route.

Hope that helps a bit

@lukeed lukeed closed this as completed Jun 29, 2021
@brev
Copy link

brev commented Sep 7, 2021

Hi @jerrythomas @lukeed,

I've done some starter work on using ESM loader hooks for this: https://github.com/brev/esm-loader-svelte

My ESM-only testing of SvelteKit with UVU is now working decently. Svelte component imports are compiled. CSS/PostCSS style imports are no-op instead of failing. JSON imports can be done with another experimental node flag.

@brev
Copy link

brev commented Sep 8, 2021

Just updated npm to a new version, it now also does preprocessing.

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

No branches or pull requests

3 participants