lawnstarter / react-native-picker-select

🔽 A Picker component for React Native which emulates the native <select> interfaces for iOS and Android
https://npmjs.com/package/react-native-picker-select
MIT License
1.74k stars 497 forks source link

Not compatible with @react-native-picker/picker v2.1.0 #458

Closed bittu1028 closed 8 months ago

ramisalem commented 2 years ago

Same issue

superguineapig commented 2 years ago

@bittu1028 @ramisalem - what are you experiencing exactly? which platform? which deps? etc...

teckbeng-payboy commented 2 years ago
Screenshot 2021-10-06 at 3 52 15 PM

Once update react-native-picker to v2.1.0, then it will show this error which probably cause by this package

Current env: "@react-native-picker/picker": "^2.1.0", "react-native-picker-select": "^8.0.4",

superguineapig commented 2 years ago

Try this as a quick troubleshooting checklist: (in order)

  1. close app in simulator if running
  2. simulator Device -> Erase all content and settings
  3. close any running instances of metro/bundler
  4. search your (*.js) codebase for old imports to @react-native-community/picker replace with @react-native-picker/picker
  5. npm uninstall @react-native-community/picker
  6. cd ios && pod install
  7. if using XCode, run aProduct -> Clean Build Folder
  8. Rebuild and run however you usually do (cli or XCode)

Double check that your package.json does not include any old/duplicate picker deps (dev too) at different versions.

You can also try to repeat the steps starting at 5, by completely removing your local node modules rm -rf node_modules then npm install and at 6 by removing your installed Pods cd ios && rm Podfile.lock && rm -rf Pods then pod install --repo-update to get fresh versions of all deps. This will take longer to do, but usually clears out any old stuff.

If you are still seeing the same error after all of this, it might be another dep in your package.json that is including the old community picker in its source.

Rehubbard commented 2 years ago

If you follow the current readme, this library will end up installing 2 versions of @react-native-picker/picker. That's what causes this issue.

I got it working by installing @react-native-picker/picker with ^1.8.3 in package.json. It has to match this library's dependency exactly or it will install duplicates and you'll get the Invariant Violation error.

I believe the dependency configuration around @react-native-picker/picker could be improved in this library.

I made a PR using @react-native-picker/picker as a peerDependency. You could also just upgrade the dependency to the latest in the current package.json (^2.1.0), but I think this is a good use of peerDependencies.

ebaynaud commented 2 years ago

If you are using Yarn, you can solve this temporarily by forcing react-native-picker-select to resolve to ^2.1.0 instead of ^1.8.3 using yarn resolutions.

In package.json, add:


  "resolutions": {
    "react-native-picker-select/@react-native-picker/picker": "^2.1.0"
  },
lfkwtz commented 8 months ago

newest version uses 2.4