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

启动Expo项目时出现Reanimated版本不匹配等错误,如何解决?

Expo项目启动错误解决方案

报错信息

[Reanimated] JavaScript部分与原生部分版本不匹配(3.0.2 vs. 2.14.4)。升级react-native-reanimated后是否忘记重新构建应用?若使用Expo Go,必须降级至Expo SDK内置的2.14.4版本。
ERROR TypeError: Cannot read property 'create' of undefined, js engine: hermes
ERROR Invariant Violation: "main"未注册。可能原因如下:

  • Metro(本地开发服务器)在错误的文件夹中运行。检查Metro是否正在运行,停止后在当前项目中重启。
  • 某个模块因错误加载失败,且未调用AppRegistry.registerComponent,js engine: hermes

一、修复react-native-reanimated版本不匹配

  • 若使用Expo Go:
    1. 卸载当前版本:npm uninstall react-native-reanimated
    2. 安装SDK适配的2.14.4版本:npm install react-native-reanimated@2.14.4
    3. 清除缓存重启:npx expo start -c
  • 若使用自定义开发构建:
    1. 确认reanimated版本与项目依赖兼容,若已升级到3.0.2,重新构建原生端:npx expo prebuild(预构建项目)或手动编译原生代码
    2. 清除缓存重启:npx expo start -c

二、解决TypeError: Cannot read property 'create' of undefined

该错误多由reanimated版本不匹配或配置缺失导致,完成上面的版本修复后一般会自动解决。若仍存在:

  • 检查babel.config.js中是否正确配置reanimated插件,且放在插件数组最后:
module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      // 其他插件
      'react-native-reanimated/plugin',
    ],
  };
};
  • 再次清除缓存重启项目:npx expo start -c

三、解决"main"未注册问题

  • 重启Metro服务器:按Ctrl+C停止当前进程,切换到项目根目录执行npx expo start
  • 检查入口文件注册逻辑:
    • 若使用原生React Native注册方式,确保index.js中调用AppRegistry.registerComponent:
    import { AppRegistry } from 'react-native';
    import App from './App';
    import { name as appName } from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
    
    • 若使用Expo,确保App.js或入口文件默认导出App组件:
    export default function App() {
      // 组件内容
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 10:52:23