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

React Native执行./gradlew assembleDebug时遇map读取未定义属性错误

React Native 构建APK时 react-native-reanimated codegen 报错 TypeError: Cannot read properties of undefined (reading 'map')

问题详情

  • 执行命令:./gradlew assembleDebug 报错,./gradlew clean 可正常执行
  • 报错任务:react-native-reanimated:generateCodegenArtifactsFromSchema
  • 错误位置:C:\Users\user\Desktop\project\project\node_modules\react-native\node_modules@react-native\codegen\lib\generators\modules\GenerateModuleJniCpp.js:439
  • 错误信息:TypeError: Cannot read properties of undefined (reading 'map')
  • 环境信息:
    • Node.js: v22.11.0
    • Android Gradle Plugin: 8.6.0
    • Gradle: 8.10.2
    • 使用的Expo模块:
      • expo-asset (11.0.1)
      • expo-constants (17.0.3)
      • expo-file-system (18.0.6)
      • expo-font (13.0.2)
      • expo-keep-awake (14.0.1)
      • expo-modules-core (2.1.2)

解决办法

1. 降低Node.js版本

Node.js v22属于较新版本,部分React Native的codegen工具暂未完全兼容。建议降级到长期支持版(LTS),比如v20.x或v18.x:

  • 用nvm切换版本:
    nvm install 20
    nvm use 20
    
  • 切换后清理依赖并重装:
    rm -rf node_modules package-lock.json yarn.lock
    npm install
    

2. 匹配react-native-reanimated版本兼容性

确保react-native-reanimated版本与你的React Native、Expo版本适配:

  • 卸载当前版本:
    npm uninstall react-native-reanimated
    
  • 安装对应Expo SDK的推荐版本(比如SDK 51对应~3.10.1):
    npm install react-native-reanimated@~3.10.1
    
  • 执行清理后重试构建:
    ./gradlew clean
    

3. 彻底清理缓存

缓存异常可能导致codegen生成失败,执行以下步骤:

  • 删除Android构建缓存:
    rm -rf android/build android/app/build
    
  • 清理npm缓存:
    npm cache clean --force
    
  • 重装依赖并构建:
    rm -rf node_modules package-lock.json
    npm install
    ./gradlew assembleDebug
    

4. 检查自定义codegen配置

如果项目中修改过codegen相关配置或schema文件,恢复默认配置后重试构建。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 06:32:40