nandorojo / expo-next-react-navigation

⛴ Make Next.js and react-navigation play nicely together with an Expo/React Native Web app.
404 stars 32 forks source link

Error: Couldn't find a navigation object. Is your component inside a screen in a navigator? #91

Closed danielkv closed 2 years ago

danielkv commented 2 years ago

Related to https://github.com/nandorojo/expo-next-react-navigation/issues/69

@nandorojo should I wrap the app with even if I'm in web with next?

I'm having the same problem here, but even I'm using only useRouting(), it's returning the same error.

Ps: I'm currently not wrapping the Next app with . Just using the standard Next navigation

danielkv commented 2 years ago

@nandorojo I managed to make it work on desktop, it worked as expected!

But reached the same problem on Expo Go. When I import directly from @react-navigation/native the hook useNavigation works, but when I import from expo-next-react-navigation or even from expo-navigation-core, the error persists, as if I'm not inside a screen navigator.

I'm wodering if it's possible to be the version of react-navigation of the lib expo-navigation-core of yours. I'm currently using @react-navigation/native v5.9.3 in my application, but in your lib it's as dependences the version 5.0.0-alpha.29.

And yes, I did install the right version of expo-next-react-navigation@v5

nandorojo commented 2 years ago

Try fixing React Navigation to the version you're using with yarn resolutions.

danielkv commented 2 years ago

I was just checkint the expo-navigation-core and I think I found out. The core of package expo-navigation-core install another version of @react-navigation/native, because it is as dependences in package.json, so it creates a different context for NavigationContainer. It happens only for the v5.

In the latest version you've removed the @react-navigation/native from the package.json, so it uses the same context as in the core app.

Would it be right to put as peerDependences?

nandorojo commented 2 years ago

Yeah, it would. Can you use yarn resolutions first to see if that solves it?

nandorojo commented 2 years ago

Dev dependencies probably makes most sense, peer deps has side effects.

nandorojo commented 2 years ago

The latest version of this library should work with v5 too actually. Try that

danielkv commented 2 years ago

Yeah, it would. Can you use yarn resolutions first to see if that solves it?

I tried, but my knowleadge on resolutions is not that good. What I tried to do was:

"resolutions": {
        "*/@react-navigation/native": "^5.9.3"
    }

I'm not even sure if it's right

danielkv commented 2 years ago

The latest version of this library should work with v5 too actually. Try that

Oh, I'm gonna try that!

danielkv commented 2 years ago

The latest version of this library should work with v5 too actually. Try that

This actually worked! I was about to give up... I'm going to do some tests here.

I'm having only a warning with file-loader/dist/cjs, I'm trying to figure it out, but it seems not to be blocking anything

Thank you very much for your time @nandorojo !

nandorojo commented 2 years ago

Happy to hear it!

danielkv commented 2 years ago

I could eventually make this work!