1

I used react-native-image-picker for fetch image form camera and photo library. i follow the steps to and link react-native-image-picker in xcode. I will code also to open imagePicker. but have an error.

Note : I will used 0.46 for react native.

Successfully link in iOS and Android.

enter image description here

My Code :

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

And onButton :

handleImagePickUp = () =>{
   ImagePicker.launchImageLibrary(options, (response)  => {
   });
}

Error :

enter image description here

Kirit Modi
  • 23,155
  • 15
  • 89
  • 112

1 Answers1

2

Instead of writing

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

you should declare ( In the same place )...

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

The rest of your code should work, although it's hard to tell since its not provided. Hope this helps, if you dont understand why this must be done let me know.

Ryan Turnbull
  • 3,766
  • 1
  • 25
  • 35
  • ok. thanks it working. but please give me explanation when import { ImagePicker } from 'react-native-image-picker' and var ImagePicker = require('react-native-image-picker'); is used. – Kirit Modi Jul 25 '17 at 08:00
  • I'm not an expert, but for this case you never use import for ImagePicker. There was a discussion on it here -> https://github.com/webpack/webpack/issues/1973 . By the way, if you ever have similar problems to this in the future, often looking into the README file in the respective node modules file ( project/node_modules/react-native-image-picker/README.md in this case ) should solve your problems – Ryan Turnbull Jul 25 '17 at 08:05