-
Notifications
You must be signed in to change notification settings - Fork 630
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
ESM project support broken in 0.76/RN 0.72 #1026
Comments
Summary: Resolves facebook#1026, resolves facebook#916. Changelog: **[Feature]** Widen config search paths to include `metro.config.cjs` Differential Revision: D47290079 fbshipit-source-id: d50c61f08580a04ad2de57092a0c77c5c5b0f22a
Hi @oblador - thanks for this, @huntie is already on the case adding support for
This is curious. I'm not aware that And just to confirm so I can reproduce, when you say "use ESM", that's by setting
Node 16 should be fine for Metro 0.76.x / RN 0.72.x. We only bumped the requirement to 18 in Metro 0.77, for RN 0.73. |
Nope there isn't, just single-step babel/metro.
Exactly!
Looked into this and tracked it down to be caused by the |
I had a chat with Aleks Andelkovic two weeks ago and he mentioned that some of the RN CLI parts were moving into metro, so maybe that's the cause? That the CLI used to support .cjs, but that now metro handles it, which never did? Found this file that seems to be somehow involved too, so maybe we should move the issue to the CLI repo? https://github.com/react-native-community/cli/blob/93b6977df378ef6d4504a207bf523af7bbd6ee6a/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts |
react-native-community/cli#1889 from @huntie seems to be the diff that introduces the error being thrown, not sure if it's the root cause. |
Ah, I think I might know what's happening. Since my config was entirely vanilla and the config itself was optional, the cjs config itself was never in use, but the project compiled fine since it fell back to defaults. Now due to some change in metro, it will not work w/o a config file and therefore having a .cjs (AKA no file) will simply not work. I can't really migrate off the ESM setup due to vite/web, so I'm effectively blocked from updating. Adding support for a .cjs config file seems like the easiest and least invasive way to unblock this (just like the related PR does). |
Got this error while upgrading my expo application to thev49 which uses RN72:
Not sure if this is related |
@oliviercperrier It looks like it's unrelated to this issue, might be worth opening up a new issue for that with a minimal reproduction 👍 |
Summary: Pull Request resolved: facebook#1027 Resolves facebook#1026. Changelog: **[Feature]** Widen config search paths to include `metro.config.cjs` Reviewed By: robhogan Differential Revision: D47290079 fbshipit-source-id: 3e46c954a1e1451558b14ed4558fede5f00200dd
I'm working in an "isomorphic" project with both react-dom and react-native, where the web part is using vite that requires ESM. To make that setup work with RN/Metro that is still heavily reliant on CJS I simply renamed the metro.config.js to metro.config.cjs to force it to resolve using CJS.
With the latest version of RN (0.72.1) this setup yields
No metro config found
, and if I rename it to.js
and use esm it throws errors originating from metro for using requires in an esm context.My guess this is originates in an update of cosmiconfig or similar. UPDATE: It seems cosmiconfig hasn't been updated in 5 years, so shouldn't be the cause.
Even though RN setup says Node 16+, metro requires 18+ so maybe this upgrade is somehow related, but with 0.71.x it works fine.
Another solution would be to properly support ESM/TS in the config as suggested in #916
The text was updated successfully, but these errors were encountered: