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

fix: support deep CJS re-exports when using ESM #13170

Merged
merged 3 commits into from Aug 25, 2022

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Aug 25, 2022

Summary

Fixes #12759

Test plan

Test added

@@ -792,9 +786,7 @@ export default class Runtime {
const namedExports = new Set(exports);

reexports.forEach(reexport => {
const resolved = this._resolveCjsModule(modulePath, reexport, {
conditions: this.esmConditions,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this specifically was the bug - we passed ESM conditions when figuring out CJS requires.

I moved all conditions into _resolveCjsModule and _resolveModule, that way this typo is way harder to make (and we always passed the same options anyways, no need for it to be an argument at all)

@@ -1,5 +1,8 @@
{
"type": "module",
"devDependencies": {
"discord.js": "14.3.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't be bothered to recreate this case, just installing the module which reproduced is easier 😅

Essentially: ESM imports CJS, which re-exports (via CJS) modules which use exports to differentiate between ESM and CJS. Jest then picked out ESM when it should have picked out CJS

@SimenB SimenB merged commit 05f6217 into jestjs:main Aug 25, 2022
@SimenB SimenB deleted the support-deep-cjs-reexports branch August 25, 2022 11:24
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: regression in v28
2 participants