Skip to content

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

Merged
SimenB merged 3 commits into
jestjs:mainfrom
SimenB:support-deep-cjs-reexports
Aug 25, 2022
Merged

fix: support deep CJS re-exports when using ESM#13170
SimenB merged 3 commits into
jestjs:mainfrom
SimenB:support-deep-cjs-reexports

Conversation

@SimenB

@SimenB SimenB commented Aug 25, 2022

Copy link
Copy Markdown
Member

Summary

Fixes #12759

Test plan

Test added


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

Copy link
Copy Markdown
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)

{
"type": "module",
"devDependencies": {
"discord.js": "14.3.0"

Copy link
Copy Markdown
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
Copy Markdown

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