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

升级react-native-reanimated至v2.0.1,如何正确配置babel插件?

React Native Reanimated v2 升级:babel.config.js 正确配置及错误修复

正确的 babel 配置方式

你之前的代码错误在于插件列表项之间缺少逗号,同时官方要求 react-native-reanimated/plugin 必须放在插件数组的最后一位。根据你的现有配置,正确写法如下:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  env: {
    production: {
      plugins: [
        'react-native-paper/babel',
        'react-native-reanimated/plugin' // 放在最后,注意前面的逗号分隔
      ],
    },
  },
  // 若开发环境也需要启用 Reanimated 插件,添加全局 plugins 配置
  // plugins: [
  //   'react-native-reanimated/plugin'
  // ]
};

如果仅需在生产环境同时启用两个插件,只修改 env.production.plugins 即可;若开发环境也需要 Reanimated 的功能,再取消注释并添加全局的 plugins 数组。

解决文件不存在的错误

你遇到的 react-native-reanimated-65.aar 不存在错误,大概率是缓存或依赖安装不完整导致的,按以下步骤修复:

  • 清除 Metro 缓存:执行 npx react-native start --reset-cache
  • 重新安装依赖:删除项目根目录的 node_modules、package-lock.json(或 yarn.lock),然后运行 npm install(或 yarn install)
  • 清理 Android 构建缓存:进入项目的 android 目录,执行 ./gradlew clean

完成以上操作后重新运行项目即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 23:06:33