-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Node.js 15.9 regression with Jest ESM #37426
Comments
I assume this is a bug in Jest's implementation which is surfaced by some added check. I'm happy to fix that if I could get some pointers to what might be wrong to cause such a warning |
Somewhat related: Maybe let's see if we can land nodejs/citgm#728 to close nodejs/citgm#684? |
Jest's tests are not failing on 15.9, so it wouldn't have caught this particular error. But yes, should definitely try to land it in CITGM regardless 👍 |
15.11 still has an issue |
I still think it's more likely to be a bug in Jest's implementation than anything, but I'm not sure where. I've had next to no time for OSS in the last few months unfortunately, so haven't found the time to dig into this |
Getting similar errors: Likely the same reason. On node 15.10.0 (macOS + Homebrew). Nice to see people are on this. Let me know if further (testing) assistance is appreciated. |
@devsnek Node.js errors about ESM linking have no stack trace right now. Jest prints stack trace if an error has it. |
@ai ...yes they do |
Sorry. My fault, I just found that I saw only ESM errors in Jest :( |
Found the issue. Pretty cool race condition. Also reproduces without 521c08d. Minimal repro: const { SourceTextModule, SyntheticModule } = require('vm');
const tm = new SourceTextModule('import "a"');
tm
.link(async () => {
const tm2 = new SourceTextModule('import "b"');
tm2.link(async () => {
const sm = new SyntheticModule([], () => {});
await sm.link(() => {});
await sm.evaluate();
return sm;
}).then(() => tm2.evaluate());
return tm2;
})
.then(() => tm.evaluate())
.then(() => {
console.log('dun');
})
.catch((e) => {
console.error(e);
}); Working on a fix.... @SimenB a good short-term fix is to only call link at the top level import, and let it automatically call the linker cb on the dependencies (and same with evaluate, you don't need to call it on each module) |
This fixes an annoying bug where the entry module would link before its dependencies were linked. This is fixed by forcing modules to wait for all dependency linker promises to resolve. Fixes: nodejs#37426 Signed-off-by: snek <me@gus.host>
This fixes an annoying bug where the entry module would link before its dependencies were linked. This is fixed by forcing modules to wait for all dependency linker promises to resolve. Fixes: nodejs#37426 Signed-off-by: snek <me@gus.host>
Actually, I'm going to have to call this working as intended. It isn't possible to solve this without also breaking circular dependencies. Jest will need to refactor its code to not link before all modules in the tree are linked. |
Cool, thanks for the pointer @devsnek!
This applies only to static imports I assume? So for dynamic imports I'd still invoke
For future reference, do |
Ok, I think I have a fix. 🤞 All of Jest's existing ESM tests pass in addition to the reproduction in this bug at least. It also has a simplification of how we handle circular dependencies, so I have high hopes this is a better implementation than the one we're currently shipping. Thank you so much for the help @devsnek! PR, for reference: jestjs/jest#11150 |
btw, are we ready to transition the VM modules API out of experimental? |
@SimenB for both static and dynamic imports, you only have to call link and evaluate on the entrypoint. You could remove the isStatic distinction in jest entirely. |
Yep, that's the approach I went for. Thanks again! 👍
I know you didn't ask me, but I think #33439 and #35714 should be solved first (especially the latter as that might need an API change?) EDIT: And probably #35889 and #36351 (which might be the same thing?) I also still have hopes for #31658 being fixed at some point, but that doesn't really affect the VM ESM APIs so might not affect any stability/flagging decision |
After upgrading Node.js 15.8 → 15.9 Jest stopped supporting ESM.
Linux foxbat 5.10.15-200.fc33.x86_64 #1 SMP Wed Feb 10 17:46:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
What do you see instead?
Additional information
The text was updated successfully, but these errors were encountered: