Skip to content
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

Updating Metro in a React Native project #940

Open
robhogan opened this issue Mar 12, 2023 · 2 comments
Open

Updating Metro in a React Native project #940

robhogan opened this issue Mar 12, 2023 · 2 comments

Comments

@robhogan
Copy link
Contributor

Opening this to track an issue raised in #1 (comment) - currently, there's no good way to update Metro independently of React Native. When people try to do this it's unlikely to work as expected, but there's no clear indication as to why.

(This mainly relates to "vanilla" React Native installs that use @react-native-community/cli, but there might be some overlap with Expo setups)

Adding a metro dependency to your package.json

⚠️ This approach generally will not work. ⚠️

@lgibso34 apologies for going off-topic but where exactly did you bump/modify the default metro version that comes with React Native?

For my app I was able to yarn install metro which added an entry in my package.json and overrode the one that RN installs within its node_modules.

This won't work because your packager (eg Yarn) will respect that your project and react-native specify dependencies on different versions of Metro, and install both. Your project's dependency will be installed at node_modules/metro, but react-native and @react-native-community/cli-plugin-metro will retain their own copies of Metro deeper within node_modules. When you run start, the latter will be used - not the version you installed.

On top of this, having multiple versions of Metro installed can cause bugs, such as in #857 (comment)

Workaround

We don't recommend using a version of Metro other than the one specified by React Native and its dependencies. But, if you want to try anyway, the only correct way to force a different version of an indirect dependency is to override it at the packager level. With Yarn classic, you can use resolutions, NPM (and PNPM) have overrides. You should override every Metro package, i.e. all of these. If folks get this working and would like to share their config here, please do!

Future plans

There's some work ongoing between the maintainers of Metro, React Native and the CLI to rearrange this dependency relationship so that users can set their Metro version and receive updates. We'll close this issue when that's complete.

@RWOverdijk
Copy link

RWOverdijk commented Mar 15, 2023

which applies to folks wanting to try symlinks before they're officially part of an RN release.

I was just curious which release that would be. Is there something we can follow?

@robhogan
Copy link
Contributor Author

React Native will have Metro with symlink support (minimum behind a flag) from 0.72. The first RC should be out this month, and you can follow that in Road to 0.72 if you like.

EvanBacon pushed a commit to expo/expo that referenced this issue Apr 13, 2023
# Why

Preemptively upgrades the `expo-template-tabs` example to `metro@0.76`. 

Expo Router has experimental features that require `metro@0.76` that we
would like users to start testing. However the documentation around
upgrading Metro within a project is lacking
(facebook/metro#940). We are upgrading just
this template for better user adoption.

These resolutions will be removed when Expo SDK supports
`react-native@0.72`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants