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

Expo ejected项目iOS模拟器报错:AsyncStorage为空及项目未注册

问题描述
  • 原Expo项目执行eject操作后,在iOS模拟器运行时出现首个错误:Error: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null
  • 尝试官方方案(卸载重建应用、--reset-cache启动打包器、iOS端执行pod install)后,出现新错误:Invariant Violation: "exampleproject" has not been registered
  • 项目版本信息:@react-native-async-storage/async-storage: ^2.0.0,react-native: ^0.74.5
  • 仅进行iOS开发,未安装Android环境,存在两个疑问:
    • 安卓调试是否能解决当前问题?
    • 已eject的项目是否需要重新安装Expo,才能使用expo install @react-native-async-storage/async-storage安装库?
解决方案

解决 NativeModule: AsyncStorage is null

  1. 重新安装并同步AsyncStorage依赖

    • 卸载现有包:npm uninstall @react-native-async-storage/async-storage
    • 用React Native原生命令重新安装:npm install @react-native-async-storage/async-storage
    • 进入iOS目录执行:cd ios && pod install && cd ..,确保Pod依赖正确同步
    • 清理Xcode构建缓存:打开Xcode,执行Product -> Clean Build Folder(快捷键Cmd+Shift+K)
  2. 规范AsyncStorage的导入与使用

    • 确保导入语句为:import AsyncStorage from '@react-native-async-storage/async-storage';,不要使用旧版react-native内置的AsyncStorage
    • 避免在组件初始化阶段同步调用AsyncStorage方法,改用异步方式(比如在useEffect钩子中执行)

解决 "exampleproject" has not been registered

  1. 校验项目名称一致性

    • 打开package.json,确认name字段值为exampleproject(与错误提示中的名称一致)
    • 打开iOS项目中的AppDelegate.mm(或.m)文件,检查moduleName参数是否与package.json的name完全匹配:
      RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                       moduleName:@"exampleproject"
                                                initialProperties:nil];
      
    • 若不一致,修改为完全匹配的名称后重新编译
  2. 彻底清理缓存并重启服务

    • 关闭Metro打包器终端窗口
    • 执行缓存清理命令:npx react-native start --reset-cache
    • 卸载iOS模拟器中的应用,重新运行项目:npx react-native run-ios
  3. 检查Xcode项目配置

    • 打开Xcode中的项目文件,确认Target的Bundle Identifier无错误
    • 检查Info.plist中的CFBundleDisplayName是否与项目名称一致
疑问解答
  1. 安卓调试是否有用?
    没用。当前错误均属于iOS端或React Native通用逻辑层问题,与Android环境无关,无需进行安卓调试。

  2. 已eject的项目能否用expo install?
    不能。eject后的项目已脱离Expo的管理体系,必须使用npm install或yarn add来安装第三方库,使用expo install会导致依赖冲突或配置异常,无需重新安装Expo。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 14:01:12