'TypeError: undefined is not an object (evaluating '_reactNativeImagePicker.default.showImagePicker')

Using React Image Picker i am facing this error: TypeError: undefined is not an object (evaluating '_reactNativeImagePicker.default.showImagePicker')

This is what happens when i click on image picker function

Mobile Screenshot:

Error Image

This is my Code:

import React from 'react';
import { View, Text,Button } from 'react-native';
import ImagePicker from 'react-native-image-picker';

const options = {
    title: 'Select Avatar',
    customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
    storageOptions: {
      skipBackup: true,
      path: 'images',
    },
  };

function Picker(){
    const openPicker =()=>{
      ImagePicker.showImagePicker(options, (response) => {
        console.log('Response = ', response);
      
        if (response.didCancel) {
          console.log('User cancelled image picker');
        } else if (response.error) {
          console.log('ImagePicker Error: ', response.error);
        } else if (response.customButton) {
          console.log('User tapped custom button: ', response.customButton);
        } else {
          const source = { uri: response.uri };
      
          // You can also display the image using data:
          // const source = { uri: 'data:image/jpeg;base64,' + response.data };
      
          console.log(source)
        }
      });
    }
    return(
        <View>
            <Button onPress={openPicker} title="Open image picker"></Button>
        </View>
    )
}

export default Picker; 


Solution 1:[1]

I had this same issue and this is how I solved it.

import * as ImagePicker from "react-native-image-picker"

Solution 2:[2]

If your react-native-image-picker version is 3.x.x then, replace the above code with these lines,

import {launchCamera, launchImageLibrary} from 'react-native-image-picker'; // Migration from 2.x.x to 3.x.x => showImagePicker API is removed.
...

const openPicker =()=>{
  launchCamera(options, (response) => { // Use launchImageLibrary to open image gallery
    console.log('Response = ', response);
  
    if (response.didCancel) {
      console.log('User cancelled image picker');
    } else if (response.error) {
      console.log('ImagePicker Error: ', response.error);
    } else if (response.customButton) {
      console.log('User tapped custom button: ', response.customButton);
    } else {
      const source = { uri: response.uri };
  
      // You can also display the image using data:
      // const source = { uri: 'data:image/jpeg;base64,' + response.data };
  
      console.log(source)
    }
  });

Read the docs

Solution 3:[3]

Issue:
import ImagePicker from "react-native-image-picker"

Solution:
import * as ImagePicker from "react-native-image-picker"

Solution 4:[4]

check your lib version if its 3x then try something like this

import * as ImagePicker from "react-native-image-picker"


                <Button onPress={() =>
                        ImagePicker.launchImageLibrary(
                          {
                            mediaType: 'photo',
                            includeBase64: false,
                            maxHeight: 200,
                            maxWidth: 200,
                          },
                          (response) => {
                            console.log(response);
                            this.setState({resourcePath: response});
                          },
                        )
                      }
                title="Select Image"/>

Solution 5:[5]

Replace

  import { ImagePicker } from 'react-native-image-picker',

with

var ImagePicker = require('react-native-image-picker');

This is working for me.

Solution 6:[6]

you can downgrade your version of the image picker library I am facing same issue then I am using this CLI command to downgrade a version of the image picker npm install [email protected] same like you can use this command

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BigData-Guru
Solution 2
Solution 3 chanduthedev
Solution 4 user889030
Solution 5 Umesh
Solution 6 Ahsan Raza Alvi