-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Wasm es6 modules fail to load with Jest, but work in Node #11011
Comments
The error is about Jest module resolution tries to resolve However, after correcting Jest module resolution, I ran into another error
which Idk how to solve. If simply solving your original error, |
Thank you for the tip! I updated the repo with the correct Any suggestions for how I can troubleshoot this issue is appreciated 🙏 |
Just now I noticed that it’s a combination of wasm + ESM. Maybe you should try jest@next first and if not working then go to the ESM tracking issue to mention this issue there. |
Ah, thanks again for the insight. Can you link me to the "ESM tracking issue"? I'm not sure what you're referring to, but happy to mention this issue there. I updated to jest@next (updated the repo linked above as well), but now I'm getting this error:
It's a different error, but it seems like we're getting closer! But I'm still not sure how to debug this 🤔 |
Jest does not support WASM at this time. I'm not sure how support would be added. Is it enough to do I have zero idea how WASM works, so I can't really do much here. Are there any JS globals available in WASM? If not I guess just executing the file and returning the result should be enough? |
I guess reading https://github.com/WebAssembly/esm-integration/tree/master/proposals/esm-integration is a start (I can almost guarantee I won't have the time or energy to work on this for some time, so if anybody wants to pick it up that'd be great!) |
Thanks everyone for the clarification! This makes much more sense now. I didn't realize that WASM isn't supported in Jest - I was a little naive in thinking that if I can load a module in Node, then I should be able to load it in Jest. I appreciate the help 🙏 |
That's how it's supposed to work, but node has added a bunch of stuff for ESM (including WASM) in the last couple of years we haven't been able to follow (especially since most is still behind flags on the Node side) |
No, JavaScript global variables are not accessible from WebAssembly by default. The earliest versions of WebAssembly did not have global variables at all. Modern WebAssembly does have global variables, and they can be shared between JavaScript and WebAssembly. |
Is anyone currently working on this? |
How have our tests been working with the WASM in |
I managed to tweak
This is obviously not a production-grade solution, but I hope it can helpful to someone. |
@kachkaev happy to take a PR if you can add some tests 🙂 some support is way better than no support |
My knowledge of My |
Fair enough. It looks like you pretty much just mapped https://github.com/nodejs/node/blob/7cdf745fddade8b7fc644f44121fbba041d3ac4c/lib/internal/modules/esm/translators.js#L322-L349 to |
Interesting! I did not see this translator so was crafting the patch in the ‘blind watchmaker’ mode 😅 Not sure I’ll have capacity to create a PR in my work hours, so unfortunately I can start it only around 22-23 Oct (the earliest). I’d be happy if someone else makes an attempt before me – feel free to recycle the demo repo. |
@SimenB I’ve started #13505, which essentially copies my experimental patch over to |
Nice! Just tested 29.3.0 against the same demo project and it worked without a local patch! 🎉 |
I'm still having a failure with |
There is a bug in the initial implementation, to do with If you see
you can use this patch for now: diff --git a/node_modules/jest-runtime/build/index.js b/node_modules/jest-runtime/build/index.js
index 9906023..d8458dd 100644
--- a/node_modules/jest-runtime/build/index.js
+++ b/node_modules/jest-runtime/build/index.js
@@ -1509,7 +1509,7 @@ class Runtime {
const moduleLookup = {};
for (const {module} of imports) {
if (moduleLookup[module] === undefined) {
- moduleLookup[module] = await this.loadEsmModule(
+ moduleLookup[module] = await this.linkAndEvaluateModule(
await this.resolveModule(module, identifier, context)
);
} UPD: Fixed via #13608 |
@knightcode can you open up a new issue? |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
I'm able to load an es6 module with Node, but I'm unable to load the same module when running with Jest. When I try loading the module with Jest, I get the following error:
To Reproduce
Steps to reproduce the behavior:
npm run test-jest
Note that running
npm run test-node
loads the module successfully in Node. So why does it fail with Jest?Expected behavior
The module loads when running
npm run test-jest
.Link to repl or repo (highly encouraged)
https://github.com/modulitos/jest-wasm-esm-example
envinfo
The text was updated successfully, but these errors were encountered: