admin管理员组

文章数量:1318979

Currently I am running my React Native project via terminal and Atom editor. I am trying to use rect-native-image-picker from and followed the instructions to install: npm install react-native-image-picker@latest --save

And my dependencies show: "react-native-image-picker": "^0.22.8"

Then I tried following the exact example, yet I am still getting an error on ImagePicker.showImagePicker(options, (response) => {...}) when I press the button to choose an image: Cannot read property 'showImagePicker' of undefined

So I console.log(ImagePicker) of import ImagePicker from 'react-native-image-picker', which is exactly how it is implemented in the Example project from react-native-image-picker, and it logged:

So I cloned the Example project and also console.log(ImagePicker) and it showed:

I am starting to believe that the issue is that I am not getting functions that I am supposed to get, such as launchCamera and launchImageLibrary. I can't seem to figure out why. What could I be missing or doing incorrectly?

Currently I am running my React Native project via terminal and Atom editor. I am trying to use rect-native-image-picker from https://github./marcshilling/react-native-image-picker and followed the instructions to install: npm install react-native-image-picker@latest --save

And my dependencies show: "react-native-image-picker": "^0.22.8"

Then I tried following the exact example, yet I am still getting an error on ImagePicker.showImagePicker(options, (response) => {...}) when I press the button to choose an image: Cannot read property 'showImagePicker' of undefined

So I console.log(ImagePicker) of import ImagePicker from 'react-native-image-picker', which is exactly how it is implemented in the Example project from react-native-image-picker, and it logged:

So I cloned the Example project and also console.log(ImagePicker) and it showed:

I am starting to believe that the issue is that I am not getting functions that I am supposed to get, such as launchCamera and launchImageLibrary. I can't seem to figure out why. What could I be missing or doing incorrectly?

Share Improve this question edited Sep 29, 2016 at 15:41 Jo Ko asked Sep 27, 2016 at 9:06 Jo KoJo Ko 7,57516 gold badges69 silver badges128 bronze badges 21
  • Did you link the dependency? rnpm link – dting Commented Sep 27, 2016 at 9:17
  • @DTing sorry but what's that? In the terminal, project folder? I actually used react-native-image-picker for a previous project and installed and implmented it the exact same, and it worked then and don't recall doing the rnpm link. – Jo Ko Commented Sep 27, 2016 at 9:21
  • See if following the rest of the instructions for the install section fixes your problem. github./marcshilling/react-native-image-picker#install – dting Commented Sep 27, 2016 at 9:27
  • @DTing I'm wondering why it worked in my previous project by simply doing npm install, and the rest of the institutions apply to Xcode but I use a terminal and an editor for the project. – Jo Ko Commented Sep 27, 2016 at 9:44
  • @DTing Please let me know if you had the chance to see my previous ment. – Jo Ko Commented Sep 27, 2016 at 19:21
 |  Show 16 more ments

4 Answers 4

Reset to default 1

What version of RN and iOS do you use? If you are sure that you linked npm package with native code (rnpm link), you can try add to your Info.plist (right key -> Open as source code) between <dict> tags:

<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>

I have also faced the same issue. So in the documentation, the auto-linking is given but it is not linking all the dependency. You need to link some dependency manually. Please follow this below link it will help you. For manually linking follow this

Do this:

import {launchCamera, launchImageLibrary} from 'react-native-image-picker';


launchCamera(options, response => {
          if (response.didCancel) {
            console.log('User cancelled image picker');
          } else if (response.error) {
            alert('ImagePicker Error: ', response.error);
          } else if (response.customButton) {
            console.log('User tapped custom button: ', response.customButton);
          } else {
            alert(response.uri)

          }
        });

The reason is that ImagePicker.showImagePicker is depreciated

I'm not an expert but you can solved this issue thanks to :

  • this tutorial showImagePicker https://dev-yakuza.posstree./en/react-native/react-native-image-picker/ & https://github./dev-yakuza/react-native-image-picker-example
  • (!) I'm on React Native >= 0.60 but the react-native-image-picker version is "react-native-image-picker": "2.3.1"
  • To use react-native-image-picker on iOS, open ios/[project name]/Info.plist and modify it like below.

I'm not an expert but you can solved this issue thanks to :

  • this tutorial showImagePicker https://dev-yakuza.posstree./en/react-native/react-native-image-picker/ & https://github./dev-yakuza/react-native-image-picker-example
  • (!) I'm on React Native >= 0.60 but the react-native-image-picker version is "react-native-image-picker": "2.3.1"
  • To use react-native-image-picker on iOS, open ios/[project name]/Info.plist and modify it like below.

Don't hesitate to remove your nodes_modules and pod files then restart your server

Don't hesitate to remove your nodes_modules and pod files then restart your server

本文标签: javascriptWhy is reactnativeimagepicker39s showImagePicker undefined in React NativeStack Overflow