Closed
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D80267431 |
robhogan
added a commit
that referenced
this pull request
Aug 15, 2025
Summary: Support ESM `metro.config.js` files, including with top-level await, with either the `.js` extension (as long as the nearest `package.json` does not have `"type": "commonjs"`), or the `.mjs` extension. ## Implementation Since Metro now requires Node.js >= 20.19, most supported versions should have backported Node-native `require(esm)` support (exception: early releases of 22.x) - this works for any sync ESM graphs, as well as of course CommonJS. When `require(esm)` throws (eg top-level await, or early Node 22), we fall back to `await import`. We could simply only use `await import()`, unfortunately the main problem with that is poor support in Jest in current Node.js (`TypeError: A dynamic import callback was invoked without --experimental-vm-modules`), which is also why we're not adding a test fixture. Changelog: ``` - **[Feature]** Support ESM `metro.config.js` / `metro.config.mjs` ``` Reviewed By: huntie Differential Revision: D80267431
dbcdad9 to
82ea0a9
Compare
Summary: Pull Request resolved: #1557 Support ESM `metro.config.js` files, including with top-level await, with either the `.js` extension (as long as the nearest `package.json` does not have `"type": "commonjs"`), or the `.mjs` extension. ## Implementation Since Metro now requires Node.js >= 20.19, most supported versions should have backported Node-native `require(esm)` support (exception: early releases of 22.x) - this works for any sync ESM graphs, as well as of course CommonJS. When `require(esm)` throws (eg top-level await, or early Node 22), we fall back to `await import`. We could simply only use `await import()`, unfortunately the main problem with that is poor support in Jest in current Node.js (`TypeError: A dynamic import callback was invoked without --experimental-vm-modules`), which is also why we're not adding a test fixture. Changelog: ``` - **[Feature]** Support ESM `metro.config.js` / `metro.config.mjs` ``` Reviewed By: huntie Differential Revision: D80267431
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D80267431 |
82ea0a9 to
ae580d8
Compare
robhogan
added a commit
that referenced
this pull request
Aug 15, 2025
Summary: Support ESM `metro.config.js` files, including with top-level await, with either the `.js` extension (as long as the nearest `package.json` does not have `"type": "commonjs"`), or the `.mjs` extension. ## Implementation Since Metro now requires Node.js >= 20.19, most supported versions should have backported Node-native `require(esm)` support (exception: early releases of 22.x) - this works for any sync ESM graphs, as well as of course CommonJS. When `require(esm)` throws (eg top-level await, or early Node 22), we fall back to `await import`. We could simply only use `await import()`, unfortunately the main problem with that is poor support in Jest in current Node.js (`TypeError: A dynamic import callback was invoked without --experimental-vm-modules`), which is also why we're not adding a test fixture. Changelog: ``` - **[Feature]** Support ESM `metro.config.js` / `metro.config.mjs` ``` Reviewed By: huntie Differential Revision: D80267431
Contributor
|
This pull request has been merged in 974d8e5. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Support ESM
metro.config.jsfiles, including with top-level await, with either the.jsextension (as long as the nearestpackage.jsondoes not have"type": "commonjs"), or the.mjsextension.Implementation
Since Metro now requires Node.js >= 20.19, most supported versions should have backported Node-native
require(esm)support (exception: early releases of 22.x) - this works for any sync ESM graphs, as well as of course CommonJS.When
require(esm)throws (eg top-level await, or early Node 22), we fall back toawait import.We could simply only use
await import(), unfortunately the main problem with that is poor support in Jest in current Node (TypeError: A dynamic import callback was invoked without --experimental-vm-modules), which is also why we're not adding a test fixture.Changelog:
Differential Revision: D80267431