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

React Native打包Debug APK时遇gesture.ts函数错误求助

解决React Native打包时child.isClassAccessorProperty is not a function错误

错误原因

该错误源于@babel/plugin-transform-typescript版本过低,不支持isClassAccessorProperty方法,或是与react-native-gesture-handler的TypeScript语法不兼容。

解决步骤

1. 适配react-native-gesture-handler版本

  • 卸载现有版本:
    npm uninstall react-native-gesture-handler
    
  • 安装与当前React Native版本兼容的稳定版:
    npm install react-native-gesture-handler
    
  • iOS项目需同步执行:
    npx pod-install
    

2. 升级Babel相关依赖

直接更新Babel核心及TypeScript转换插件:

npm update @babel/core @babel/plugin-transform-typescript @babel/traverse

3. 清理缓存并重建依赖

  • 重置React Native缓存:
    npx react-native start --reset-cache
    
  • 删除旧依赖文件(Windows系统替换为rmdir /s /q node_modules && del package-lock.json yarn.lock):
    rm -rf node_modules package-lock.json yarn.lock
    
  • 重新安装依赖:
    npm install
    

4. 检查Babel配置

确保babel.config.js使用Metro预设,避免手动添加冲突插件:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  // 若使用reanimated,保留以下插件(按需添加)
  plugins: ['react-native-reanimated/plugin'],
};

完成以上步骤后,重新执行打包命令即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 14:25:30