You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
volta install node@15.8
node --experimental-vm-modules node_modules/.bin/jest
(node:60479) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS ./index.test.js
✎ todo test
Test Suites: 1 passed, 1 total
Tests: 1 todo, 1 total
Snapshots: 0 total
Time: 0.173 s
Ran all test suites.
What do you see instead?
volta install node@15.9
node --experimental-vm-modules node_modules/.bin/jest
(node:60418) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
FAIL ./index.test.js
● Test suite failed to run
linking error, dependency promises must be resolved on instantiate
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
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
@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)
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.
@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 applies only to static imports I assume? So for dynamic imports I'd still invoke link and evaluate manually? In that case, what about a dynamic import that has its own static import? Should I only call link and evaluate on the first import and then on dynamic imports, but let all static imports "do its own thing"?
i've never used jest before. how do i make it print a proper stack trace instead of just the error message?
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!
@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! 👍
btw, are we ready to transition the VM modules API out of experimental?
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
Activity
targos commentedon Feb 18, 2021
/cc @devsnek
Could it be that #37300 did have an effect on the public API after all?
SimenB commentedon Feb 18, 2021
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
Trott commentedon Feb 19, 2021
I did a
git bisecton this issue and it is indeed that commit where the problem was introduced.521c08d
Trott commentedon Feb 19, 2021
Somewhat related: Maybe let's see if we can land nodejs/citgm#728 to close nodejs/citgm#684?
SimenB commentedon Feb 19, 2021
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 👍
ai commentedon Mar 3, 2021
15.11 still has an issue
SimenB commentedon Mar 3, 2021
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
akauppi commentedon Mar 4, 2021
Getting similar errors:
linking error, not in local cache. akauppi/firebase-jest-testing#5Likely 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 commentedon Mar 4, 2021
i've never used jest before. how do i make it print a proper stack trace instead of just the error message?
ai commentedon Mar 4, 2021
@devsnek Node.js errors about ESM linking have no stack trace right now.
Jest prints stack trace if an error has it.
devsnek commentedon Mar 4, 2021
@ai ...yes they do
ai commentedon Mar 4, 2021
Sorry. My fault, I just found that I saw only ESM errors in Jest :(
devsnek commentedon Mar 4, 2021
Found the issue. Pretty cool race condition. Also reproduces without 521c08d.
Minimal repro:
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)
devsnek commentedon Mar 4, 2021
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.
SimenB commentedon Mar 4, 2021
Cool, thanks for the pointer @devsnek!
This applies only to static imports I assume? So for dynamic imports I'd still invoke
linkandevaluatemanually? In that case, what about a dynamic import that has its own static import? Should I only calllinkandevaluateon the first import and then on dynamic imports, but let all static imports "do its own thing"?For future reference, do
return lineshere (or rather in the associated transpiled .js version) instead of thefilter: https://github.com/facebook/jest/blob/024295c49ec7ac5baa6de1ec1888ce29a5d0c35f/packages/jest-message-util/src/index.ts#L191SimenB commentedon Mar 4, 2021
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
targos commentedon Mar 4, 2021
btw, are we ready to transition the VM modules API out of experimental?
devsnek commentedon Mar 4, 2021
@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.
SimenB commentedon Mar 6, 2021
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