我已经安装了包react-native-image picker:
npm i react-native-image-picker --save我还将它链接到我的项目:
react-native link react-native-image-picker当我尝试导入模块并使用它时:
import ImagePicker from 'react-native-image-picker';
ImagePicker.launchImageLibrary(options, (response) => {
// code here
}我收到以下错误:
typeError: Cannot read property 'launchImageLibrary' of undefined这里出了什么问题?
发布于 2020-12-11 02:01:38
您应该仔细检查此npm包的最新文档,因为它已迁移到较新的版本。旧的2.x.x版本已被弃用,正如在包的GitHub页面中所写的那样,因此关键模块的名称可能已经更改...
发布于 2021-01-28 08:33:29
对于3.x版本,可以直接导入如下函数
import {launchImageLibrary} from 'react-native-image-picker';在一个世博会项目中,我仍然遇到了相同的错误,比如this issue (因为lauchImageLibrary来自NativeModules.ImagePickerManager)。但它在使用React Native CLI初始化的项目中工作得很好。
发布于 2021-03-02 15:54:39
下面是它的解决方案,
import {launchImageLibrary} from 'react-native-image-picker';
const changePhoto = () => {
const options = {
noData: true,
};
launchImageLibrary(options, (response) => {
console.log(response);
});
};
<TouchableOpacity onPress={changePhoto}>
<Text>Change Photo</Text>
</TouchableOpacity>https://stackoverflow.com/questions/65239308
复制相似问题