react-native-safe-area-context icon indicating copy to clipboard operation
react-native-safe-area-context copied to clipboard

Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider

Open karimcambridge opened this issue 5 years ago β€’ 25 comments

πŸ‘‰ jump to the solution

karimcambridge avatar Jun 26 '20 04:06 karimcambridge

Same issue here @karimcambridge, do you have found a solution?

AleeeKoi avatar Jun 30 '20 14:06 AleeeKoi

Nope,. I reverted back as noone seems to know why yet. Not many people are getting the issue.

karimcambridge avatar Jun 30 '20 14:06 karimcambridge

ok, @karimcambridge can you explain what you have reverted? Thank you

In my case, I'm starting a new expo project and simply installing react navigation (following the official guide). I can see that simply importing import { createStackNavigator } from '@react-navigation/stack'; in my navigation file generate the error.

AleeeKoi avatar Jun 30 '20 14:06 AleeeKoi

Oh wow.

I'm not sure

I was on expo sdk 37 so I just reverted my package.json and ran npm install

karimcambridge avatar Jun 30 '20 14:06 karimcambridge

Well, downgrading to sdk 37 make it works. I will wait with you for a solution.

AleeeKoi avatar Jun 30 '20 15:06 AleeeKoi

I'm seeing this with react-navigation and Expo SDK 38 as well. For some reason Expo has this lib (and no others) in it's node_modules. As a workaround to get my project working, I removed it from there. Not sure where the fault lies though.

chrisscott avatar Jul 01 '20 23:07 chrisscott

Getting the same issue, you guys found any solution yet.. may be we need to open this issue on expo repo.. also if downgrading to sdk 37 works, then please tell me whats the latest version of sdk 37 as expo's github release history is confusing.

sam17896 avatar Jul 02 '20 20:07 sam17896

It looks like Expo 38.0.8 fixed this. Targeting that version in my project and doing an npm install resolved this.

chrisscott avatar Jul 02 '20 21:07 chrisscott

It looks like Expo 38.0.8 fixed this. Targeting that version in my project and doing an npm install resolved this.

Unfortunately not for me I'll dig more tonight.

sam17896 avatar Jul 03 '20 16:07 sam17896

I created a sample app that demonstrates the issues: https://github.com/ikakara/expo-sdk38-bug

ikakara avatar Jul 04 '20 07:07 ikakara

I can confirm that we're experiencing this issue on a non-expo app (react-native init app). We ran into it while attempting to upgrade to react-navigation v5. We also upgraded react-native-safe-area-context at the same time. I do not have a good lead yet on the cause from our end...it looks like it could be coming from the @react-navigation/compat package but i'm not very certain on that yet.

conrad-vanl avatar Jul 06 '20 19:07 conrad-vanl

@conrad-vanl I had the same issue and it was a problem with react-navigation. I fixed it by updating react-navigation-stack to 2.8.2 and react-navigation-tabs to 2.9.0.

henrypigg avatar Jul 09 '20 07:07 henrypigg

Removing react-native-safe-area-context from expo.dependencies in package-lock and running npm install fixed this for me. Expo and react-navigation 5.

jasonserafino avatar Jul 09 '20 20:07 jasonserafino

It looks like Expo 38.0.8 fixed this. Targeting that version in my project and doing an npm install resolved this.

This solves the issue for me. I also removed expo app from simulator and let it install again

neiker avatar Jul 12 '20 16:07 neiker

It works on ver.3.0.7, with SDK38 + React Navigation 5.

Upgrading to ver.3.1.1 breaks the app :/

HristoEftimov avatar Jul 13 '20 08:07 HristoEftimov

For me the following worked:

  • Delete react-native-safe-area-contex from package.json

  • Removed node modules rm -rf node_modules

  • Run npm install

iNeedHookah avatar Jul 14 '20 17:07 iNeedHookah

I just started a new project on SDK 38 (38.0.8). Installed safe-area-context version 3.0.7 and it still breaks.

pastordougdev avatar Jul 17 '20 19:07 pastordougdev

I noticed I have two versions/copies of react-native-safe-area-context, one inside the project's package.json and the other is inside expo's. So I have finally solved this problem the following way:

  1. Go to expo's own node_modules, remove the react-native-safe-area-context from there
  2. Remove react-native-safe-area-context from package.json for expo's folder in node_modules
  3. Run again using expo r -c.

Note: this problem usually happens when you remove node_modules and reinstall them.

kalideir avatar Jul 18 '20 02:07 kalideir

For now, I added this inside "scripts" in my package.json "postinstall":"rm -rf node_modules/expo/node_modules/react-native-safe-area-context",

It's an ugly fix but does the job.

dominik992 avatar Jul 22 '20 15:07 dominik992

@pastordougdev - can you provide a reproducible example?

i just did this and it worked as expected:

╭─~/code
╰─$ expo init testingit
? Choose a template: expo-template-blank

🧢 Using Yarn to install packages. You can pass --npm to use npm instead.

βœ” Downloaded and extracted project files.
βœ” Installed JavaScript dependencies.

βœ… Your project is ready!

To run your project, navigate to the directory and run one of the following yarn commands.

- cd testingit
- yarn start # you can open iOS, Android, or web from here, or run them directly with the commands below.
- yarn android
- yarn ios
- yarn web
╭─~/code
╰─$ cd testingit
╭─~/code/testingit β€Ήmasterβ€Ί
╰─$ expo install react-native-safe-area-context
Installing 1 SDK 38.0.0 compatible native module using Yarn.
> yarn add react-native-safe-area-context@~3.0.7
yarn add v1.22.4
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ”¨  Building fresh packages...
success Saved 0 new dependencies.
✨  Done in 2.67s.

the key things here:

  • expo package is [email protected]
  • install react-native-safe-area-context with expo install react-native-safe-area-context

still having this problem?

  • delete node_modules and your lockfile (package-lock.json / yarn.lock)
  • change the expo package version in package.json to 38.0.8
  • remove react-native-safe-area-context from your package.json
  • run yarn or npm install
  • run expo install react-native-safe-area-context

brentvatne avatar Jul 22 '20 17:07 brentvatne

expo version 38.0.9 solved the problem.

xcode-one avatar Aug 01 '20 14:08 xcode-one

Below worked for me:

Removing package-lock,json and node_module delete entry of "react-native-safe-area-view": "^1.1.1" from package.json run "npm install"

Post that i was not getting this error while launching app on ios device.

pkj-ind avatar Aug 03 '20 13:08 pkj-ind

Below worked for me:

Removing package-lock,json and node_module delete entry of "react-native-safe-area-view": "^1.1.1" from package.json run "npm install"

tried the same, but does not work. But I also cannot see version 38.0.8. It is only showing me 38.0.0 And if I then try to "install expo-secure-store" I am getting a new error:

"action persist/PERSIST" which simply stays on my terminal window while the expo app on the iPhone crashes

Anyone could help please?

TagIt34 avatar Aug 03 '20 14:08 TagIt34

@pastordougdev - can you provide a reproducible example?

i just did this and it worked as expected:

╭─~/code
╰─$ expo init testingit
? Choose a template: expo-template-blank

🧢 Using Yarn to install packages. You can pass --npm to use npm instead.

βœ” Downloaded and extracted project files.
βœ” Installed JavaScript dependencies.

βœ… Your project is ready!

To run your project, navigate to the directory and run one of the following yarn commands.

- cd testingit
- yarn start # you can open iOS, Android, or web from here, or run them directly with the commands below.
- yarn android
- yarn ios
- yarn web
╭─~/code
╰─$ cd testingit
╭─~/code/testingit β€Ήmasterβ€Ί
╰─$ expo install react-native-safe-area-context
Installing 1 SDK 38.0.0 compatible native module using Yarn.
> yarn add react-native-safe-area-context@~3.0.7
yarn add v1.22.4
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ”¨  Building fresh packages...
success Saved 0 new dependencies.
✨  Done in 2.67s.

the key things here:

  • expo package is [email protected]
  • install react-native-safe-area-context with expo install react-native-safe-area-context

still having this problem?

  • delete node_modules and your lockfile (package-lock.json / yarn.lock)
  • change the expo package version in package.json to 38.0.8
  • remove react-native-safe-area-context from your package.json
  • run yarn or npm install
  • run expo install react-native-safe-area-context

Nice, Guy~

iNorthSea avatar Aug 04 '20 14:08 iNorthSea

still having this problem?

  • run expo install react-native-safe-area-context
  • run yarn or npm install

brentvatne avatar Aug 04 '20 22:08 brentvatne