0

I was tasked with updating the React Native version of a monorepo application from 0.71.12 to 0.73.0. I used the React Native Upgrade Helper as per the documentation, but I’m stuck with an issue that I can’t seem to resolve.

The app compiles fine, but when I start Metro and run yarn android in another terminal, I get the following error:

  • Invalid hook call warning
  • Cannot read property 'useContext' of null

Here’s what I’ve already tried:

  • Ensured no conflicting versions of react, react-native, or react-dom across the monorepo.
  • Added a resolutions section in the root package.json.
  • Verified that I’m not breaking any hook rules.
  • Confirmed that the Android SDK is correctly set up.
  • Made sure that I updated all the files according to the Upgrade Helper.

What’s weird is that everything works fine if I revert back to version 0.71.12. It seems completely tied to the version upgrade.

What could be causing this?

Cannot read property 'useContext' of null error screen

Invalid Hook Call warning

3
  • Hooks can only be called inside the body of a function component.You might be breaking the Rules of Hooks. Could you share the code that uses the useContext hook ? Currently, I am unable to recommend a solution without seeing your code. Commented Aug 20, 2024 at 4:55
  • Had a similar situation resolved by deleting node modules and reinstalling, have you tried that? Commented Aug 21, 2024 at 11:42
  • Yes, I've tried deleting node_modules and reinstalling several times, I don't know how it could be Invalid Hook issue, since with the previous version of react native works without issue, already validated it just in case, and don't see any rules being broken. Commented Aug 21, 2024 at 16:47

1 Answer 1

1

After literal weeks of trying different things, the issue was with metro. Apparently the way they handle module resolution completely changed from one version to another, making the my metro.config.js obsolete. 1 This was only briefly mentioned on the official documentation, and the information that finally solved my issue was that enableGlobalPackages is disabled by default now, causing all sorts of issues and duplications. In this case there was a 'react' module both on packages/app and on the source project.

This wasn't showing up with any of the commands to check for duplicated or mismatching versions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.