Skip to content

fix(cjs-esm-interop): support module.exports in ESM#16277

Open
avivkeller wants to merge 2 commits into
jestjs:mainfrom
avivkeller:cjs-esm-interop
Open

fix(cjs-esm-interop): support module.exports in ESM#16277
avivkeller wants to merge 2 commits into
jestjs:mainfrom
avivkeller:cjs-esm-interop

Conversation

@avivkeller

Copy link
Copy Markdown

Summary

Hi! Today, I learned by using an ESM export such as the one below, you can write a CommonJS compatible script in ECMAScript modules:

export { myVariable as "module.exports" }

Now, when require-ing this module, myVariable will be returned.

However, Jest does not duplicate this behavior, so I figured I'd upstream a patch to rectify that.

Test plan

To test this, I added a few new test files (for the CJS Loader and ESM Loader), and ran yarn test.

@netlify

netlify Bot commented Jul 12, 2026

Copy link
Copy Markdown

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 77635b0
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6a5318fc56af34000877d82a
😎 Deploy Preview https://deploy-preview-16277--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the require-changelog If a PR does requires a changelog entry label Jul 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@16277

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@16277

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@16277

create-jest

npm i https://pkg.pr.new/create-jest@16277

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@16277

expect

npm i https://pkg.pr.new/expect@16277

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@16277

jest

npm i https://pkg.pr.new/jest@16277

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@16277

jest-circus

npm i https://pkg.pr.new/jest-circus@16277

jest-cli

npm i https://pkg.pr.new/jest-cli@16277

jest-config

npm i https://pkg.pr.new/jest-config@16277

@jest/console

npm i https://pkg.pr.new/@jest/console@16277

@jest/core

npm i https://pkg.pr.new/@jest/core@16277

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@16277

jest-diff

npm i https://pkg.pr.new/jest-diff@16277

jest-docblock

npm i https://pkg.pr.new/jest-docblock@16277

jest-each

npm i https://pkg.pr.new/jest-each@16277

@jest/environment

npm i https://pkg.pr.new/@jest/environment@16277

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@16277

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@16277

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@16277

@jest/expect

npm i https://pkg.pr.new/@jest/expect@16277

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@16277

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@16277

@jest/globals

npm i https://pkg.pr.new/@jest/globals@16277

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@16277

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@16277

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@16277

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@16277

jest-message-util

npm i https://pkg.pr.new/jest-message-util@16277

jest-mock

npm i https://pkg.pr.new/jest-mock@16277

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@16277

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@16277

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@16277

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@16277

jest-resolve

npm i https://pkg.pr.new/jest-resolve@16277

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@16277

jest-runner

npm i https://pkg.pr.new/jest-runner@16277

jest-runtime

npm i https://pkg.pr.new/jest-runtime@16277

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@16277

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@16277

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@16277

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@16277

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@16277

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@16277

@jest/transform

npm i https://pkg.pr.new/@jest/transform@16277

@jest/types

npm i https://pkg.pr.new/@jest/types@16277

jest-util

npm i https://pkg.pr.new/jest-util@16277

jest-validate

npm i https://pkg.pr.new/jest-validate@16277

jest-watcher

npm i https://pkg.pr.new/jest-watcher@16277

jest-worker

npm i https://pkg.pr.new/jest-worker@16277

pretty-format

npm i https://pkg.pr.new/pretty-format@16277

commit: 77635b0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

require-changelog If a PR does requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant