35

When I am trying to use import {createStackNavigator} from @react-navigation/stack, it gives me an error

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

I have tried finding a solution, but nothing helps.

enter image description here

1

20 Answers 20

54

Invariant Violation: Tried to register two views with the same name RNCSafeAreaProvider error with @react-navigation/stack

It means you have installed same extension multiple times.

Running "npm dedupe" command solved my problem.

or Yarn install (The dedupe command isn’t necessary. yarn install will already dedupe.)

4
  • 2
    If you are using yarn, it says: error The dedupe command isn't necessary. yarn install will already dedupe. Commented May 3, 2021 at 4:20
  • 2
    npm deduce fixed my issue
    – Cuado
    Commented Aug 6, 2021 at 8:16
  • 1
    i use yarn install and it doesn't work. but npm dedupe works Commented Jan 8, 2022 at 17:41
  • this worked to get me running on Android, but IOS still doesn't work... so weird! Thanks doe! Commented Jan 20, 2023 at 14:07
19

For my case, two different masked-view packages in package.json caused it:

"@react-native-community/masked-view": "0.1.10",
"@react-native-masked-view/masked-view": "0.2.4",

ReactNavigation5 requires @react-native-community/masked-view, while react-native-skeleton-placeholder has the other as the prerequisite. So, watching your dependencies, you can remove one of those to get rid of this error.

15

Just running

expo upgrade

solved my issue.

2
  • Editor's note: do not rollback or override edits from community members that improve formatting and/or syntax and spelling. In your case, the user fixed formatting misuse. Code blocks should not be formatted as quotes, much less as nested quotes. Commented Aug 18, 2021 at 8:03
  • I ran into this problem when I upgraded my project using npm-check-updates. That is obviously not the correct way of doing it for Expo projects. Now using expo upgrade all is good. Thanks!
    – eigil
    Commented Sep 17, 2021 at 13:50
14

reinstalling react-native-safe-area-context did the trick for me in EXPO.

2
  • This works for me too
    – AyoDavid
    Commented Dec 7, 2021 at 20:08
  • Worked for me when upgrading to expo 51 Commented Jun 13 at 23:07
8

There have been few fixes on Github for this package issues on resolving the above dreadful error, which one of it happens to work for me. I'll highlight a couple of fixes here and follow the link for more.

Follow these steps to fix it, but I only tried the last part:

  • delete node_modules and your lock file (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

The below step works for me.

  • run expo install react-native-safe-area-context

Thanks to brentvatne.

2
  • 2
    the line that helped me: expo install react-native-safe-area-context Commented Dec 9, 2021 at 23:13
  • I'd very much recommend you not delete your lock file. That can cause major issues with your application far beyond what they may or may not fix.
    – Artif3x
    Commented Nov 9, 2022 at 17:30
4

package.json adding in scripts npm dedupe worked for me .

1
  • 2
    This appears to be simply confirming that this answer worked. That means it is not an answer, of itself, and shouldn't be posted as one. Commented Sep 24, 2021 at 13:18
3

In my case I forgot to add one line which is import 'react-native-gesture-handler'; on top of the file in index.js

if you don't install it so you have to install it first by using the command npm install react-native-gesture-handler

OR

yarn add react-native-gesture-handler

1
  • When I upgraded react-navigation from 3-4 I forgot to include this. Thanks.
    – zachary
    Commented Feb 11, 2022 at 15:06
3

Even though its already answered I'll provide a solution that worked for me.

"react-native-safe-area-context" is probably causing a conflict with Navigation Container.

Removing "safe-area-context" solved the issue temporarily for me and its probably the way for a more permanent solution.

Im a React-Native beginner but this is my input to help other people with similar issues.

1
  • This was the exact issue I was facing. Now, according to reactnavigation.org/docs/handling-safe-area, react-native-safe-area-context is required to support navigation. This is what I did to solve mine: 1. deleted 'react-native-safe-area-context' from my 'package.json' 2. ran 'yarn' 3. ran 'expo install react-native-safe-area-context' . This will ensure that expo adds this package itself, since the conflict was btw 'expo' and 'react-native'
    – Okpo
    Commented Dec 17, 2021 at 7:40
3

I was having the same problem with react-native-safe-area-context. So I searched for it in my yarn.lock and found out that some other lib was using a different version of safe-area-context than the one I had in my package.json

react-native-gifted-chat was using version 4.2.4 of react-native-safe-area-context

I had version 3.3.2 in my package.json

So I updated my package.json to use the same version (4.2.4) and it worked

0
2

What worked for me was uninstalling react-native-elements and reinstalling them.

react-native-safe-area-context has a module inside of react-native-elements, which caused caused the duplicate error.

The other answers worked only temporarily but the error would continue to appear

2

it works for me version sdk(42.0.0) ❤️❤️❤️🥳🥳😉

here is the solution :)

open your app route folder ==> node_modules ==> invariant ==> browser.js

in browser.js file remove the [if condition code] (line number 28 to 46 )

my package.json file given below :

"expo": "~42.0.1",

"react": "16.13.1",

"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",

"react-native-safe-area-context": "3.1.9",

2

it works for me version SDK(42.0.0)

here is the solution :)

open your app route folder ==> node_modules ==> invariant ==> browser.js

in browser.js file remove the [if condition code] (line number 28 to 46 )

my package.json file given below :

"expo": "~42.0.1",

"react": "16.13.1",

 "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",

"react-native-safe-area-context": "^3.3.0",
"react-native-screens": "^3.5.0",
0
1

In the pack-lock.json file, remove the react-native-safe-area-context. That will solve the problem.

The code will look like this:

  "react-native-elements": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/react-native-elements/-/react-native-elements-3.1.0.tgz",
      "integrity": "sha512-U4CuyO+q2JlduPht4P0xz+oIbw3W53uYPpkMqvlwjJiVoFfwnpbAu+JZL01/7VMe98G4Y8nJImcBh7zK9cb3Uw==",
      "requires": {
        "@types/react-native-vector-icons": "^6.4.6",
        "color": "^3.1.2",
        "deepmerge": "^4.2.2",
        "hoist-non-react-statics": "^3.3.2",
        "lodash.isequal": "^4.5.0",
        "opencollective-postinstall": "^2.0.3",
        "prop-types": "^15.7.2",
        "react-native-ratings": "^7.3.0",
        "react-native-safe-area-context": "^3.1.9",
        "react-native-size-matters": "^0.3.1"
      },
      "dependencies": {
        "deepmerge": {
          "version": "4.2.2",
          "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz",
          "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg=="
        },
        "opencollective-postinstall": {
          "version": "2.0.3",
          "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz",
          "integrity": "sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q=="
        },
        ---> "react-native-safe-area-context": { <--- remove this
          "version": "3.1.9",
          "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-3.1.9.tgz",
          "integrity": "sha512-wmcGbdyE/vBSL5IjDPReoJUEqxkZsywZw5gPwsVUV1NBpw5eTIdnL6Y0uNKHE25Z661moxPHQz6kwAkYQyorxA=="
        }
      }
    },

1

For me it worked using the commands:

npm dedupe
expo update
1
  • npm dedupe was enough for me Commented Jan 13, 2022 at 18:35
1

Okay, this might seem a little wacky hacky, and I'm not quite sure how or why it worked, but it did. I tried pretty much all the answers here and got nowhere.

Note: I had ./package.json in my directory already from when my app previously threw this error, see below

For some reason, if do the following:

  1. I run Yarn, allow it to create ./yarn.lock and ./node_modules
  2. THEN I run npm i which creates the ./package-lock.json file
  3. Run expo start, my app loads...

I don't think this is good practice but it worked for me. Here's my ./package.json which I had in my directory BEFORE I ran yarn/went through the steps in the order above:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@babel/runtime": "7.0.0-beta.55",
    "@react-native-async-storage/async-storage": "^1.15.9",
    "@react-native-community/netinfo": "6.0.0",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/drawer": "^6.1.4",
    "@react-navigation/native": "^6.0.2",
    "aws-amplify": "^4.2.5",
    "aws-amplify-react-native": "^5.0.3",
    "expo": "~42.0.1",
    "expo-status-bar": "~1.0.4",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-reanimated": "~2.2.0",
    "react-native-safe-area-context": "3.2.0",
    "react-native-screens": "~3.4.0",
    "react-native-web": "~0.13.12"
  },
  "devDependencies": {
    "@babel/core": "~7.9.0"
  },
  "private": true
}

If it works for anyone that visits, cool, if someone could explain or attempt to repeat this and comes up with an explanation please share.

0

is here is the solution

Comented the line

open your app route folder ==> node_modules ==> invariant ==> browser.js

in browser.js file remove the [if condition code] (line number 28 to 46 )

0
  1. Run expo install react-native-safe-area-context
  2. Run yarn install or npm install
0

This error also appears if you move your navigation and screens across files.

You can solve this by just running the command below if you are using expo or its equivalent it bare React Native app.

expo start --clear
0

This github issue comment helped me. Basically, in my package.json I just went to the react-native-safe-area-context dependency, and changed my version 4.6.3 to ^4.6.3 and ran yarn/npm install again, and re-ran the project. Instant success.

-2

step 1: delete your node modules Step 2: install node modules using yarn instead of npm install

Now,your issue Fixed

Not the answer you're looking for? Browse other questions tagged or ask your own question.