Skip to content

[Bug]: failure of import of ESM package when called from CJS project - #16329

Open
tsushanth wants to merge 1 commit into
jestjs:mainfrom
tsushanth:fix/-Bug-failure-of-import-of-ESM-package-wh-1786295231
Open

[Bug]: failure of import of ESM package when called from CJS project#16329
tsushanth wants to merge 1 commit into
jestjs:mainfrom
tsushanth:fix/-Bug-failure-of-import-of-ESM-package-wh-1786295231

Conversation

@tsushanth

Copy link
Copy Markdown
Contributor

in CjsLoader.requireModule, catch resolveCjs failures and retry with resolveEsm when supportsSyncEvaluate is true, allowing require() of ESM-only packages (with only "import" export condition) to work on Node 24.9+

Found via automated repo scanning, fix written and reviewed before opening.

@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 61f04d9
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6a83f5666f8cb3000815b487
😎 Deploy Preview https://deploy-preview-16329--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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 Aug 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

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

babel-plugin-jest-hoist

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

babel-preset-jest

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

create-jest

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

@jest/diff-sequences

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

expect

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

@jest/expect-utils

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

jest

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

jest-changed-files

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

jest-circus

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

jest-cli

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

jest-config

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

@jest/console

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

@jest/core

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

@jest/create-cache-key-function

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

jest-diff

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

jest-docblock

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

jest-each

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

@jest/environment

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

jest-environment-jsdom

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

@jest/environment-jsdom-abstract

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

jest-environment-node

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

@jest/expect

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

@jest/fake-timers

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

@jest/get-type

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

@jest/globals

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

jest-haste-map

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

jest-jasmine2

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

jest-leak-detector

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

jest-matcher-utils

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

jest-message-util

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

jest-mock

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

@jest/pattern

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

jest-phabricator

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

jest-regex-util

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

@jest/reporters

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

jest-resolve

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

jest-resolve-dependencies

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

jest-runner

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

jest-runtime

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

@jest/schemas

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

jest-snapshot

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

@jest/snapshot-utils

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

@jest/source-map

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

@jest/test-result

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

@jest/test-sequencer

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

@jest/transform

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

@jest/types

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

jest-util

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

jest-validate

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

jest-watcher

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

jest-worker

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

pretty-format

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

commit: 61f04d9

@tsushanth
tsushanth force-pushed the fix/-Bug-failure-of-import-of-ESM-package-wh-1786295231 branch from ee774fe to 76c80fb Compare August 13, 2026 08:24
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 13, 2026

Copy link
Copy Markdown

CLA Not Signed

@tsushanth

Copy link
Copy Markdown
Contributor Author

recheck

@SimenB SimenB left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is right - the only shape this catch triggers for is one Node itself rejects. resolveCjs throws when "exports" has an "import" branch and no require/default/module-sync, and require() of such a package in plain Node gives:

ERR_PACKAGE_PATH_NOT_EXPORTED  No "exports" main defined in .../node_modules/esm-only-pkg/package.json

With this patch Jest loads it. Tests passing where production throws is the wrong direction for a test runner.


This made me realise we're missing module-sync condition tho - I'll add that 🙂

@tsushanth
tsushanth force-pushed the fix/-Bug-failure-of-import-of-ESM-package-wh-1786295231 branch 3 times, most recently from 03fb541 to ede7ed7 Compare August 17, 2026 15:41
@tsushanth
tsushanth force-pushed the fix/-Bug-failure-of-import-of-ESM-package-wh-1786295231 branch from ede7ed7 to 61f04d9 Compare August 18, 2026 06:02
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.

3 participants