react-native-safe-area-context: New solution for locked issue #110: Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider
The old solution: https://github.com/th3rdwave/react-native-safe-area-context/issues/110#issuecomment-668864576
New solution: just run expo install react-native-safe-area-context and then yarn or npm install. Should fix the problem by installing a newer version of react-native-safe-area-context (in my case, 3.1.4).
I would have updated the original issue, but it’s locked.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 15
Yup I had this issue as well, using Expo SDK 39 and react-navigation 4.x
It appears Expo comes with react-native-safe-area-context in it’s own node_modules folder, but react-navigation was complaining about
Unable to resolve "react-native-safe-area-context" from "node_modules/react-navigation-stack/lib/module/vendor/views/Stack/StackView.js"until it was installed with
expo install react-native-safe-area-context.This appeared to work fine with Android when running the app, even though there were now 2 versions present in the dependancy tree after checking with
npm list react-native-safe-area-context.iOS however gave this error described here when booting up the app:
Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider.For a quick and dirty solution for now, i’ve added
"postinstall": "rm -rf node_modules/expo/node_modules/react-native-safe-area-context"underscriptsin package.json to remove the Expo one, and now the app is running fine.I’m sure there must be a better solution out there by someone more versed in this than myself 😃
i tried everything, no one solution worked in IOS ( didn’t try yet in Android).
i’ve expo bare workflow, expo-cli 3.26.2 and “expo”: “~38.0.8”,
same issue:
please help, is 2 days i m stock!
so i don t know the reason but i did installed react-native-safe-area-view with react-native-safe-area-context together and it worked for now, here the steps:
I had an issue where
react-native-safe-area-contextwas included in the dependencies of a dependency and as a direct dependencyI had it in
package-lock.jsonreact-native-elementswhich introduced the duplicate dependency. Removing that manually fixed the issue.only remove the previous one and install it with expo install react-native-safe-area-context it works for me.
I can say @juho-ylikyla solution and delete
rm -rf node_modules/react-native-elements/node_modules/react-native-safe-area-contextworks for meI have the same issue using an using React-Native-CLI. I wrote a simple UI library package “A” based on “react-native-elements”, then I try to use package “A” in an React-Native-CLI app. the app uses “@react-navigtion” so I have to add react-native-safe-area-context 3.1.9 as dependency. Then I run into “Tried to register two views with the same name RNCSafeAreaProvider”. “react-native-elements” also require react-native-safe-area-context 3.1.9, I think the version I installed is correct, not sure where the problem is. Any guidence or thoughts are appricated.
package.json of my libary package.
{ name: “A” … “dependecies”:{ “react-native-elements”: “^3.1.0” } … }
package.json of my app. { … “dependecies”:{ “@react-native-community/masked-view”: “^0.1.10”, “@react-navigation/native”: “^5.8.10”, “@react-navigation/stack”: “^5.12.8”, “react”:“16.13.1”, “react-native”:“0.63.4”, “react-native-gesture-handler”:“^1.9.0”, “react-native-safe-area-context”: “3.1.9”, “react-native-screens”: “^2.16.1”, “react-native-vector-icons”: “^7.1.0” “A”:“0.0.1”
} … }
Finally managed to solve this issue, in case anyone else is having the same problem I did. The error was in fact correct that there were 2 versions installed. However, I had previously deleted the wrong one (the one in /node_modules). I’m using expo, and what ended up working was deleting the copy in /node_modules/expo/node_modules/, as well as its reference in package-lock.json.