Skip to content

Transform ES modules in Node package files under Jest - #60035

Open
lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-60029-jest-node-files-esm
Open

lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-60029-jest-node-files-esm

Conversation

@lazerg

@lazerg lazerg commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Summary:

jest/preprocessor.js runs files under metro-* package paths through the metro-babel-register options with sourceType: 'script'. In script mode the CommonJS transform skips the file, so import/export in packages/metro-config/src/index.flow.js stay as they are and any test that requires @react-native/metro-config fails with SyntaxError: Cannot use import statement outside a module. This switches it to 'unambiguous', like the React Native branch below it already uses, so ES module files get transformed and CommonJS files stay scripts.

Fixes #60029

Changelog:

[INTERNAL] [FIXED] - Transform ES modules in Node package files in the Jest preprocessor

Test Plan:

Added packages/metro-config/src/__tests__/index-test.js, which loads @react-native/metro-config from source. It fails on main with the SyntaxError from the issue and passes with this change. yarn test shows the same results as on main (generate-artifacts-executor-test.js and one InspectorProxyCdpRewritingHacks-test.js case also fail on main on my machine). yarn flow focus-check, eslint and prettier are clean on the changed files.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 16, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

1 visual difference(s) at ace56fa33391. Visual differences need maintainer approval. Review the report, then apply visual-change-approved.

ios button/default-styling/default: Changed, 2492802 px (100.000%)

diff

Expected and Captured
Expected Captured
expected captured

This branch has not been deployed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

1 participant