feat(metro-config)!: enable experimentalImportSupport
by default
#30005
+2,118
−2,110
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.
Why
In SDK 52 and greater, we should try to enable
experimentalImportSupport
by default. This feature converts import/export syntax to use Metro runtime equivalents in a secondary Babel pass. This aligns with how Metro is used internally at Meta, and fixes some broken behavior in the Metro transform pipeline.When
experimentalImportSupport
is disabled, the babel plugins@babel/plugin-transform-modules-commonjs
and@babel/plugin-proposal-export-default-from
are used to emulate the behavior but with@babel/runtime
equivalents. This leads to substantially more imports and breaks the"use strict"
directive injection since all modules are viewed as commonjs.When this flag is enabled
lazyImports
is silently ignored. Which raises some other questions. It appears we currently discard the internal list of lazy imports by React Native. I'd imagine the RN list is there to emulate a subset ofinlineRequires
behavior. When bundling a React Native iOS app however, it doesn't appear that any of the modules in the RN list are ever invoked. This seems like an artifact of when React Native migrated from using Haste-style importsView
to standard imports like./View
.For us, the only notable change is that imports on
expo
,expo-asset
, andexpo-task-manager
will no longer default to being lazily initialized.expo
andexpo-assets
should never have been in this list since they both contain root side-effects that must be imported at an exact time. Not sure if anything breaks by movingexpo-task-manager
, can't imagine how it might.Syntax changes
module
(like we do in expo-maps) will not work anymore.Test Plan