Repository navigation
fix(jest-runtime, @jest/transform): improve ESM error handling on Node < 24.9 - #16244
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
ebcf055 to
6f056f4
Compare
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
SimenB
left a comment
There was a problem hiding this comment.
looks great, thanks! just left a few comments 🙂
…e < 24.9 Signed-off-by: Jon Koops <jonkoops@gmail.com>
6f056f4 to
bc8e8e7
Compare
|
Code coverage failures seem unrelated to this PR, everything else is green, so I think this is good to go. |
|
Thanks for landing this, @SimenB. Is there a release scheduled for Jest anytime soon? |
|
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. |
Summary
Jest 30.4's ESM runtime rewrite gates
require()of ESM-marked files ("type": "module"or.mjs) behindsupportsSyncEvaluate, which requires Node 24.9+. On older Node, this immediately throwsERR_REQUIRE_ESM, bypassing the transform pipeline entirely. This breaks projects that rely on a configured transform (e.g. babel-jest) to convert ESM dependencies to CJS (backstage/backstage#34182).This PR:
supportsSyncEvaluatecheck into the outer condition so ESM-marked files fall through to the CJS path on older Node. If the configured transform converts the file,require()succeeds.ERR_REQUIRE_ESMerror with actionable guidance (configure a transform or upgrade to Node v24.9+), replacing the generic "Jest encountered an unexpected token" message.enhanceUnexpectedTokenMessagein@jest/transform, since all valid ESM cases are intercepted by the newERR_REQUIRE_ESMerror.Cleaner reimplementation of #16240.
Test plan
Unit and e2e tests added covering:
testWithSyncEsm)testWithoutSyncEsm)ERR_REQUIRE_ESMfor untransformed ESM-marked packages (testWithoutSyncEsm)testWithoutSyncEsm)ERR_REQUIRE_ESMfor untranspiled node_modules with ESM syntax