react-native-image-picker: TypeError: Cannot read property 'launchImageLibrary' of undefined [🐛]
Description
Getting error TypeError: Cannot read property 'launchImageLibrary' of undefined calling launchImageLibrary() on versions 5.3.0, 5.2.0 and 5.1.0.
Downgrading to version 5.0.0 and 4.10.x I’m getting an error on build (which probably has already been addressed).
It works on version 4.8.5.
How to repeat issue
Installed the library npm install react-native-image-picker
Tried to import it in different ways
import {launchImageLibrary} from 'react-native-image-picker';
import * as ImagePicker from 'react-native-image-picker';
var ImagePicker = require('react-native-image-picker');
Called the function directly or with async
const handleImagePicker = () => {
ImagePicker.launchImageLibrary(
{includeBase64: true},
(res) => console.log(res)
);
}
const handleImagePicker = async () => {
const res = await ImagePicker.launchImageLibrary(
{includeBase64: true},
(res) => console.log(res)
);
console.log(res);
}
Additional Information
- Image Picker version: 5.3.0
- React Native version: 0.64.4
- Platform: Android
- Development Operating System: Windows
- Dev tools: Android SDK 30
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 7
- Comments: 26
import { launchCamera, launchImageLibrary } from ‘react-native-image-picker’
or
import * as ImagePicker from ‘react-native-image-picker’
Same problem here. The issue is from this code in node_modules/react-native-image-picker/src/platforms/native.ts
–> NativeModules.ImagePicker returns null
“react-native-image-picker”: “5.6.1”, “react”: “16.13.1”, “react-native”: “0.64.4”,
My temporary solution after updating to Android SDK 33 is to upgrade react-native-image-picker to version 5.0.0 and use react-native-permissions package to handle READ_MEDIA_IMAGES permission. This works for me.
Upgrading targetSDKVersion to 33.
import { launchImageLibrary } from ‘react-native-image-picker’;
This fixed for me.
@totoledao if anything, 5.0.2 should work fine on your version of RN. The new arch was introduced in 5.1.0, which may (I don’t think it does) have a dependency on a newer version of RN.
This solution is working for me
Updated following packages: “react-native”: “0.72.4”, (https://react-native-community.github.io/upgrade-helper/ it will help you with updating RN) “react-native-image-picker”: “7.0.0”,
You might facing with this issue (IOS) -
*/node_modules/react-native-image-picker/ios/ImagePickerManager.h:1:9 Could not build module 'React'This solution helped me with issue above - https://github.com/react-native-image-picker/react-native-image-picker/issues/2158#issuecomment-1694787594I am facing with the similar to this problem I’m getting both “Cannot read property ‘launchImageLibrary’ of null” and “Cannot read property ‘launchCamera’ of null”
“react-native-image-picker”: “5.6.1”, “react-native”: “0.72.4”,
The error is catching in the file - node_modules/react-native-image-picker/src/platforms/native.ts
after switch to
targetSdkVersion = 33we had to bump the version in order to build. Started getting errorCannot read property 'launchImageLibrary' of undefined. version 5.0.2 works for us (we are using a older version of RN)Same issue here, tried pod install and all of the mentioned import methods.
“react-native-image-picker”: “^5.4.0”, “react”: “18.2.0”, “react-native”: “0.71.6”, platform: ios
@Johan-dutoit I looked at the example app & can’t really tell what’s different or wrong in our app that it doesn’t work, any hints or things that one should look for?
@lufke I am seeing this on iOS & have tried rebuilding several times.
I’d suggest looking at the example app @priyeshshah11. That is running RN0.71.2 and the latest version of the picker without this issue.