Implement async dependency resolution
See original GitHub issueSimilar to #9504, but for dependency resolution. Like there, this wouldn’t be used by Jest just yet, but could (and would, if support is implemented) be used by the ESM support. This logic is implemented in jest-resolve.
~I wonder if it makes sense to reintroduce resolve as a dependency since this already has an async code path. That is callback based, but just promisifying that should work fine. But the increased complexity of mjs, cjs etc makes me want to depend on a dedicated module rather than have that complexity live in Jest itself - Jest should just manipulate resolution based on moduleNameMapper etc and possibly cache some stuff on our side.~
~resolve was actually removed in #4315, via #2925. Some of #2925 reasoning was that resolve was somewhat unmaintained and that we didn’t need the async parts of it - neither of which are true anymore.~
Added in #9520
import.meta.resolve has landed on node master (https://github.com/nodejs/node/pull/31032, albeit currently behind a flag), so we’ll need to implement this regardless of whether we’d want to use it ourselves or not
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8 (1 by maintainers)

Top Related StackOverflow Question
Is there any roadmap on implementing this? I believe it’s having quite a significant knock on effect with build tools that wish to use Jest but cannot, Vite being one example.
PRs are very much welcome! 👍
Similar to how we did async transform (#9889), you can start by adding support to
jest-resolve, the module that does the reoslution in Jest. That means adding async APIs to https://github.com/facebook/jest/blob/26cb29a42cc9b967f29d70d8c70169993965cf01/packages/jest-resolve/src/index.ts#L51 and https://github.com/facebook/jest/blob/26cb29a42cc9b967f29d70d8c70169993965cf01/packages/jest-resolve/src/defaultResolver.ts#L34-L37Note that
resolvedoes not have a promise API which is what we want injest-resolve, but using its callback API should be fine (there is https://github.com/browserify/resolve/issues/210, but not much movement) as long as teh API exposed byjest-resolveis promise based.Once
jest-resolvesupports it we can add support to Jest by modifyingjest-runtime. Feel free to look into it of course, but I suspect that will fall to me as the code there is quite complex. But of course if you’re up for it I’d love for you to pick that up as well 👍