【问题标题】:TypeError: null is not an object for ZeroconfTypeError: null 不是 Zeroconf 的对象
【发布时间】:2019-08-08 09:19:07
【问题描述】:

我正在为 Android 开发 React Native,并且正在使用 Zeroconf。在过去的两天里,我一直在尝试迁移到 Expo SDK 34,并且已经解决了大部分问题。但是,我遇到了以下错误:

TypeError:TypeError:null 不是对象(评估“RNZeroconf.scan”)
-node_modules/react-native-zeroconf/dist/index.js:1:4265 在扫描中

Expo SDK 32 上运行时我没有出现此错误。相关代码位:

    import Zeroconf from 'react-native-zeroconf'

    componentDidMount(){
       this.zeroconf = new Zeroconf()
       this.startDockScan()
    }

    startDockScan=()=>{
       this.zeroconf.scan('http','tcp','local.'); //this is where the error traces back to
    }

【问题讨论】:

    标签: react-native expo zeroconf


    【解决方案1】:

    如果您没有弹出Expo,则无法使用此模块。

    因为你必须link这个模块到AndroidiOS文件夹。

    1. 有两种方法可以解决它。一种是弹出Expo 然后是link 模块。
    2. 另一件事是你可以使用React Native创建一个项目 然后去做。

    第一种申请方式Android

    1. Expo eject
    2. react-native link react-native-zeroconf
    

    第二种申请方式Android

    1. react-native init yourproject
    2. cd yourproject && yarn add react-native-zeroconf && react-native link react-native-zeroconf
    3. and run react-native
    

    如果你什么都不想要,你必须找到另一个模块。

    【讨论】:

    • 我在整个开发过程中一直遵循第一种方式。我通过再次设置项目解决了这个问题(删除 Android/iOS + node_module 文件夹,运行 npm_install,弹出,然后链接),但此后遇到了其他问题。升级 Expo 版本很痛苦。
    • @cfire19045 升级expo的问题根本不是你问的问题 选择我的回答结束问题,新建一个。
    猜你喜欢
    • 2013-09-25
    • 2017-01-24
    • 2021-05-08
    • 2021-11-02
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多