You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native使用react-native-android-wifi报isEnabled of undefined错误如何解决

问题解决方法

你遇到的TypeError: Cannot read property 'isEnabled' of undefined报错,核心是react-native-android-wifi导入方式错误,其次可能存在原生模块未链接、运行平台不兼容的问题,按以下步骤排查即可解决:

1. 修正导入语句

这个库使用默认导出而非命名导出,你现有的导入语句import { wifi } from 'react-native-android-wifi'会导致wifi变量为undefined,改成以下写法即可:

import wifi from 'react-native-android-wifi';

修改后你可以在componentDidMount的console.log(wifi)输出中确认wifi对象已经正确加载,不再是undefined。

2. 确认原生模块已正确链接

  • 如果你使用的React Native版本低于0.60,需要手动执行链接命令后重新打包运行:
    react-native link react-native-android-wifi
    
  • 如果你使用的React Native版本≥0.60,自动链接完成后需要重新同步安卓项目的Gradle依赖,再重新打包运行应用。

3. 确认运行平台为安卓

react-native-android-wifi是安卓专属库,仅支持安卓平台运行,如果在iOS模拟器/真机上调试会直接抛出模块未定义的错误。

按以上步骤修改后,重新运行应用即可正常调用库内的所有API。

内容的提问来源于stack exchange,提问作者DEVIL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 23:09:04