已安装react-native-image-picker,出现“TypeError: null is not an object”错误。

huangapple go评论49阅读模式
英文:

Installed react-native-image-picker, getting "TypeError: null is not an object"

问题

我正在尝试安装 react-native-image-picker。我的 package.json 包含以下内容:

    "expo": "~48.0.15",
    "react": "18.2.0",
    "react-native-image-picker": "^5.3.1",
    "react-native": "0.71.8",

到目前为止,我对这个的实现相对简单:

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

...

const handleChoosePhoto = async () => {
    const result = await ImagePicker.launchImageLibrary({});
    console.log(result);
}

[稍后有一个 TouchableOpacity 调用 handleChoosePhoto onPress]

当我尝试这样做时,我收到以下错误消息:TypeError: null is not an object (evaluating 'nativeImagePicker.launchImageLibrary') - 有什么提示可以尝试吗?

我正在 Expo 开发构建上尝试这个。我尝试过更新 react-native(从 0.70.5 到 0.71.8)和 expo(从 47 到 48)。我还在安装 react-native-image-picker 后运行了 npx pod-install

奇怪的是,当我尝试使用 expo-image-picker 库时,我得到了一个非常类似的错误。我是否需要重新创建开发构建,因为我安装了新的 RN 库?

英文:

I'm trying to install react-native-image-picker. My package.json includes these:

    "expo": "~48.0.15",
    "react": "18.2.0",
    "react-native-image-picker": "^5.3.1",
    "react-native": "0.71.8",

My implementation of this so far is relatively simple:

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

...

    const handleChoosePhoto = async () => {
        const result = await ImagePicker.launchImageLibrary({});
        console.log(result);
    }

[Later on, there's a TouchableOpacity that calls handleChoosePhoto onPress]

When I try this out, I get the error: TypeError: null is not an object (evaluating 'nativeImagePicler.launchImageLibrary') - any tips on what to try?

I'm trying this on an Expo development build. I've tried updating react-native (was on 0.70.5, now on 0.71.8) and expo (from 47 to 48). I've also done an npx pod-install after installing react-native-image-picker.

Oddly, when I try the expo-image-picker library instead, I get a very similar error. Do I have to recreate the development build, since I installed a new RN library?

答案1

得分: 1

  1. 我猜问题的一部分是尝试在Expo中使用react-native-image-picker。相反,我应该尝试使用expo-image-picker。
  2. 我在使用expo-image-picker时遇到了类似的问题,但通过构建一个新的开发构建来解决了它(其他SO问题链接)。
英文:

This is not the fullest answer, but...

  1. I'm guessing part of the problem is trying to use react-native-image-picker with Expo. Instead, I should be trying expo-image-picker
  2. I encountered a similar problem with expo-image-picker, but solved it by building a new development build (link to other SO question)

huangapple
  • 本文由 发表于 2023年5月21日 02:16:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296732.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定