GetStream / stream-chat-react-native

💬 React-Native Chat SDK ➜ Stream Chat. Includes a tutorial on building your own chat app experience using React-Native, React-Navigation and Stream
https://getstream.io/chat/sdk/react-native/
Other
969 stars 324 forks source link

"Invalid Hook Call" error when using OverlayProvider w/ streamchat 3.0 #541

Closed choibles closed 3 years ago

choibles commented 3 years ago

Describe the bug When including the as directed in the tutorial (just inside the NavigationContainer from react-navigation), an error is thrown to crash the app which says "Invalid Hook Call"

Dev environment info (please complete/provide the following information):

To Reproduce Steps to reproduce the behavior:

Install stream-chat-react-native and include OverlayProvider in App.js right inside the NavigationContainer exported from react-navigation.

Expected behavior Expected the app to load w/ the OverlayProvider context.

Additional context Yea, so investigation into this led me to the react page on the "Invalid Hook Call" warning, which suggested running npm ls react in the project folder to see if there was more than one React in the project. My output was as follows:

├─┬ @react-native-community/cameraroll@4.0.2
│ └── react@16.13.1 deduped
├─┬ @react-native-community/clipboard@1.5.1
│ └── react@16.13.1 deduped
├─┬ @react-native-picker/picker@1.9.10
│ └── react@16.13.1 deduped
├─┬ @stream-io/flat-list-mvcp@0.0.9
│ └── react@16.13.1 deduped
├─┬ react-native-image-resizer@1.4.3
│ └── react@16.13.1 deduped
├─┬ react-native-reanimated@2.0.0
│ └── react@16.13.1 deduped
├── react@16.13.1
└─┬ stream-chat-react-native@3.0.0
  ├─┬ react-native-fs@2.16.6
  │ └─┬ react-native-windows@0.57.2
  │   └── react@16.13.1 deduped invalid
  └─┬ stream-chat-react-native-core@3.0.0
    ├─┬ @gorhom/bottom-sheet@3.0.0-alpha.0
    │ ├─┬ react-native-redash@15.11.1
    │ │ └── react@16.13.1 deduped
    │ └── react@16.13.1 deduped
    ├─┬ react-art@16.13.1
    │ └── react@16.13.1 deduped
    ├─┬ react-dom@16.14.0
    │ └── react@16.13.1 deduped invalid
    └── react@16.13.1 invalid

Of particular note is the "invalid" call-outs down below stream-chat-react-native-core. I checked the package.json for stream-chat-react-native-core and noticed that there are a host of devDependencies and specifically, that react is included as a "devDependency", when the article reference above seems to indicate that libraries should declare react as a "peerDependency" instead.

I attempted to get around this by using npm-force-resolutions, but wasn't able to effect a working solution. Admittedly, it's possible this may be an error on my end (and will continue poking around), but wanted to note to library maintainers in case the devDependencies declaration was erroneous and it should be switched to a peer dependency.

Thanks!

Screenshots unnamed

gz#9915

nhannah commented 3 years ago

@choibles could you send your full package file? I think there may be a mismatch in the react versions. It is normal to include react as both a dev and peer dependency. The dev dependency should only be installed if you are developing the project; you can see the same patter in the react-native project for instance.

choibles commented 3 years ago

Hey @nhannah, thanks for touching base, and that's a good point re: the react-native repo. Here's our package.json. Appreciate your time and help!

  "name": "phoenix",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "prepare": "patch-package",
    "android-build-release": "cd ./android && ./gradlew app:assembleRelease",
    "android-devices": "adb reverse tcp:8081 tcp:8081 && adb devices"
  },
  "dependencies": {
    "@bankify/react-native-animate-number": "^0.2.1",
    "@elastic/app-search-javascript": "^7.5.0",
    "@expo/react-native-action-sheet": "^3.4.1",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "^1.7.1",
    "@react-native-community/blur": "^3.4.1",
    "@react-native-community/cameraroll": "^4.0.0",
    "@react-native-community/clipboard": "^1.5.1",
    "@react-native-community/masked-view": "^0.1.5",
    "@react-native-community/netinfo": "^5.9.5",
    "@react-native-community/push-notification-ios": "^1.8.0",
    "@react-native-firebase/analytics": "^7.6.8",
    "@react-native-firebase/app": "^8.4.6",
    "@react-native-firebase/auth": "^9.3.1",
    "@react-native-firebase/crashlytics": "^8.4.10",
    "@react-native-firebase/firestore": "^7.8.7",
    "@react-native-firebase/functions": "^7.4.9",
    "@react-native-firebase/perf": "^7.4.9",
    "@react-native-firebase/storage": "^7.4.10",
    "@react-native-picker/picker": "^1.9.10",
    "@react-navigation/bottom-tabs": "^5.11.2",
    "@react-navigation/drawer": "^5.11.4",
    "@react-navigation/native": "^5.8.10",
    "@react-navigation/stack": "^5.12.8",
    "@segment/analytics-react-native": "^1.2.1",
    "@segment/analytics-react-native-firebase": "^1.2.1",
    "@segment/analytics-react-native-mixpanel": "^1.2.1",
    "@stream-io/flat-list-mvcp": "^0.0.9",
    "chroma-js": "^2.1.0",
    "compare-versions": "^3.6.0",
    "dayjs": "^1.9.8",
    "deep-object-diff": "^1.1.0",
    "expo-av": "^8.6.0",
    "expo-screen-orientation": "^2.0.0",
    "expo-sms": "^8.3.1",
    "file-patch": "^0.3.0",
    "formik": "^2.1.4",
    "getstream": "^5.0.5",
    "js-base64": "^3.6.0",
    "libphonenumber-js": "^1.7.29",
    "lodash": "^4.17.15",
    "lottie-ios": "^3.1.9",
    "lottie-react-native": "^3.5.0",
    "moment": "^2.24.0",
    "patch-package": "^6.2.2",
    "postinstall-prepare": "^1.0.1",
    "prop-types": "^15.7.2",
    "psl": "^1.8.0",
    "react": "16.13.1",
    "react-content-loader": "^5.1.0",
    "react-native": "0.63.4",
    "react-native-buffer-image-size": "^0.6.5",
    "react-native-contacts": "^6.0.3",
    "react-native-device-info": "^6.2.1",
    "react-native-document-picker": "^4.1.0",
    "react-native-fast-image": "^8.3.2",
    "react-native-fix-image": "^2.0.1",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-get-random-values": "^1.5.0",
    "react-native-haptic-feedback": "^1.8.2",
    "react-native-image-crop-picker": "^0.35.3",
    "react-native-image-picker": "^2.3.3",
    "react-native-image-progress": "^1.1.1",
    "react-native-image-resizer": "^1.4.3",
    "react-native-inset-shadow": "^1.0.2",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-localize": "^1.3.4",
    "react-native-markdown-display": "^6.1.6",
    "react-native-marquee": "^0.3.2",
    "react-native-modal": "^11.5.3",
    "react-native-onesignal": "^3.9.0",
    "react-native-permissions": "^3.0.0",
    "react-native-pie": "^1.1.2",
    "react-native-push-notification": "^7.0.0",
    "react-native-rate": "^1.2.4",
    "react-native-reanimated": "^2.0.0",
    "react-native-safe-area-context": "^3.1.9",
    "react-native-screens": "^2.16.1",
    "react-native-section-list-get-item-layout": "^2.2.3",
    "react-native-select-contact": "^1.5.0",
    "react-native-shake": "^3.5.0",
    "react-native-share": "^5.1.4",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^12.1.0",
    "react-native-svg-transformer": "^0.14.3",
    "react-native-unimodules": "^0.11.0",
    "react-native-vector-icons": "^6.6.0",
    "react-native-webp-format": "^1.1.2",
    "recombee-js-api-client": "^3.1.0",
    "rfdc": "^1.1.4",
    "rn-fetch-blob": "^0.12.0",
    "stream-chat": "^3.1.3",
    "stream-chat-react-native": "^3.0.0",
    "styled-components": "^5.1.0",
    "throttle-debounce": "^2.1.0",
    "url": "^0.11.0",
    "uuid": "^3.3.3",
    "yup": "^0.28.0"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/runtime": "^7.8.4",
    "@react-native-community/eslint-config": "^1.1.0",
    "babel-jest": "25.1.0",
    "babel-plugin-styled-components": "^1.10.7",
    "eslint": "^6.8.0",
    "eslint-config-airbnb": "^18.0.1",
    "eslint-config-prettier": "^6.9.0",
    "eslint-plugin-import": "^2.19.1",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.2",
    "eslint-plugin-react": "^7.20.0",
    "eslint-plugin-react-hooks": "^1.7.0",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "0.59.0",
    "prettier": "^1.19.1",
    "react-test-renderer": "16.13.1",
    "reactotron-react-native": "^4.0.3"
  },
  "jest": {
    "preset": "react-native"
  }
}
choibles commented 3 years ago

Hi – just wanted to note that I resolved this by switching to yarn for dep mgmt. It was somehow able to resolve the dependencies that npm could not. Thanks for the help anyway!

spyshower commented 3 years ago

I have the same problem. Can't use the package

NicholasBoccuzzi commented 3 years ago

I had the same issue -- I switched to yarn after @choibles mentioned it was a fix for them and the error is no longer occurring. @choibles do you know why this might be the case?

And @nhannah, is there any intention to resolve the issue? When attempting to follow the first tutorial provided through the getstream website, I was immediately met with the same error @choibles shared above: https://getstream.io/chat/react-native-chat/tutorial/

npm version: 7.20.3

tsirlucas commented 3 years ago

Fixed on v3.7.3