Tried to register two views with the same name RNGestureHandlerButton
Note this answer was written for Expo v33. Please check with the current documentation for react-navigation and the version of Expo that you are using for up-to-date installation instructions.
The reason for your error is that you are using react-navigation
in your Expo app, however you have followed the tutorial incorrectly.
https://reactnavigation.org/docs/en/getting-started.html
If you read the instructions it tells you that once you have installed react-navigation
you should then install react-native-gesture-handler
. However that is not what they say
Next, install react-native-gesture-handler. If you’re using Expo you don’t need to do anything here, it’s included in the SDK.
It says that if you are using Expo
you do not need to install react-native-gesture-handler
as it is already installed.
You are getting errors because you have installed react-native-gesture-handler
, it already exists in Expo, and Expo is getting confused about where to get its information from.
To solve your problem do the following.
- Close all terminals running
Expo
- Close the browser window running
Expo
- Clear the project you were working on from the
Expo
app on your device. - Delete your
package-lock.json
- Delete your
node_modules
folder - Remove the
react-native-gesture-handler
entry from yourpackage.json
- Run
npm i
- Restart
Expo
usingexpo start -c
Be careful when using Expo
it is easy to install dependencies that cannot run with it, and cause yourself issues like this.
If you are NOT using expo and saw this error, then you may be using a component which return's a TouchableOpacity. You may get the same error and several script bundling will also happen. To fix that wrap the TouchableOpacity within a View.
So I'm using expo SDK32 and had the same issue.
I tried:
rm -rf node_modules && npm install
with no luck.- Removing
react-native-gesture-handler
from yourpackage.json
and doingrm -rf node_modules && npm install
with no luck...
I had success by making sure my version of react-native-gesture-handler
was only allowing patch changes in the semver.
old package.json line (when name collision error was happening):
"react-native-gesture-handler": "^1.0.12",
(The ^
here tells npm to bump to highest minor version, which installed version 1.4.1
)
new package.json line (fixed the error for me):
"react-native-gesture-handler": "~1.0.12",
(The ~
here tells npm to only bump the highest patch version, which installed 1.0.17
and the error was gone)
I'm assuming some kind of collision was happening having different minor versions?
I think this is what @feihcsim was talking about in their answer.
For anyone else who gets here searching for:
"Unable to resolve "react-native-gesture-handler" from "node_modules@react-navigation\native\src\Scrollables.js""
I found the answer here:
https://github.com/expo/expo/issues/5107
If you're using Expo SDK 34+, despite what older threads says, you need to run the following to get it working:expo install react-native-gesture-handler