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

Expo新架构项目中react-native-mmkv实例创建失败问题求助

问题

在启用新架构(New Architecture)的Expo项目中使用react-native-mmkv时,遇到以下错误:

(NOBRIDGE) ERROR Error: Failed to create a new MMKV instance: The native MMKV Module could not be found.

  • Make sure react-native-mmkv is correctly autolinked (run npx react-native config to verify)
  • Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md
  • Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.

项目版本信息:

{
  "react-native": "0.76.5",
  "expo": "~52.0.18",
  "react-native-mmkv": "^3.1.0"
}

已采取的步骤:

  • 在项目中启用新架构
  • 确认react-native 0.76.5版本支持TurboModules
  • 执行npx expo prebuild --clean清理并重建项目

需要解决该错误,确保react-native-mmkv在启用新架构的Expo项目中正常工作。

解决方案
  • 配置CodeGen依赖
    检查项目根目录的package.json,确保包含codegenConfig字段并声明react-native-mmkv为依赖:

    "codegenConfig": {
      "name": "YourAppSpecs",
      "type": "all",
      "jsSrcsDir": "src",
      "android": {
        "javaPackageName": "com.your.app.id"
      },
      "dependencies": [
        "react-native-mmkv"
      ]
    }
    

    若缺失该字段,添加后重新执行npx expo prebuild。

  • 确认新架构全局启用
    打开app.json(或app.config.js),确保Android和iOS端都开启新架构:

    "android": {
      "newArchEnabled": true
    },
    "ios": {
      "newArchEnabled": true
    }
    

    同时确认开发环境满足要求:Android需安装NDK 25及以上版本,iOS需使用Xcode 15.0及以上版本。

  • 验证并修复模块链接
    执行npx react-native config,查看输出中是否存在react-native-mmkv的配置项,确认其原生模块路径正确。若未找到该配置,重新安装依赖:

    npm uninstall react-native-mmkv
    npm install react-native-mmkv
    npx expo prebuild --clean
    
  • iOS端专项检查
    进入iOS目录执行pod install --repo-update,确保MMKV的Pod被正确安装;打开Xcode,将项目Build Settings中的ENABLE_BITCODE设置为NO。

  • Android端专项检查
    打开android/app/build.gradle,确认newArchEnabled = true;执行以下命令清理构建缓存:

    cd android && ./gradlew clean
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 14:53:13