-
Notifications
You must be signed in to change notification settings - Fork 886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ESM react-native.config
files
#2167
Comments
FWIW, we intend to update cosmiconfig in Metro to support Related: facebook/metro#916 |
@robhogan so it looks like we're blocked on Metro? Please keep us updated, we'd happily implement this |
I wouldn't say blocked - I can't think of any technical reason this couldn't go into the CLI before Metro, although it might be less surprising if we were consistent. I just wanted to share the experience we had with this upgrade - it might be that you're similarly blocked by Jest under Node<20, if you have integration tests that don't mock out cosmiconfig. |
Yes, we have - and I tried updating |
@robhogan seems like that issue is now resolved - in case this should be noted anywhere as this blocker being removed. |
Unfortunately it's only resolved for Node 20, and won't be backported, so it'll need to wait until we're on Node 20 (for CI, at least - there's probably no risk in prod as long as we don't use this in a Node VM). |
Ok, thanks for the answer! So I guess it's waiting until Taking a quick look in those repos, maybe that is tracked here?
Or does this also have to do with the cli/.github/workflows/test.yml Line 30 in 61b6be6
cli/.github/workflows/test.yml Line 47 in 61b6be6
|
Describe the Feature
I'd love to use modern ESM code in my React Native apps and libraries. The CLI's config package currently blocks having
"type": "module"
in a React Native app or library package, because the config command loads config files synchronous, with a ~ 5 year old version ofcosmiconfig
.Setting
"type": "module"
in apackage.json
of an app or dependency yields the following error:Users cannot rename
react-native.config.js
toreact-native.config.cjs
because it's not in the list of files being searched for, even when patching that list, yields this error:So, there doesn't seem to exist any workaround for this.
Possible Implementations
I believe the best solution is to upgrade
cosmicconfig
to a more recent version and use their async API to load the config file.This entails that the following methods would become
async
:Which would in practice break the API of both the
@react-native-community/cli
and@react-native-community/cli-config
packages and probably require a major version bump.A less intrusive alternative, would be to upgrade but only support CommonJS configs and simply add
react-native.config.cjs
and fix the issue loading it.Note: Upgrading
cosmicconfig
would have the added benefit of packages being able to declare their React Native configs in their package.json files too. But that should either be disabled or named differently to avoid conflicts with thereact-native
main field already relied upon by Metro.I'd be willing to contribute a PR to fix this, if there's a good chance it'll be considered for review.
Related Issues
I'm surprised, but I can't seem to find existing issues mentioning this limitation.
The text was updated successfully, but these errors were encountered: