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

升级Expo SDK遇TypeError及main未注册错误的排查解析

Expo升级后__expo_module_name__未定义及"main"未注册错误的解决方案

问题概述

从停止维护的Expo 45版本升级后,运行应用时触发以下两个核心错误:

ERROR  TypeError: Cannot read property '__expo_module_name__' of undefined, js engine: hermes
ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro(本地开发服务器)在错误目录运行。检查Metro状态,停止后在当前项目重启。
* 模块加载失败导致`AppRegistry.registerComponent`未调用, js engine: hermes

排查过程

  1. 查阅官方排障文档后未找到有效解决路径
  2. 执行yarn why react-native-safe-area-context排查依赖情况,输出结果如下:
yarn why v1.22.19
[1/4] 🤔  Why do we have the module "react-native-safe-area-context"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "react-native-safe-area-context@4.5.0"
info Has been hoisted to "react-native-safe-area-context"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "1004KB"
info Disk size with unique dependencies: "1004KB"
info Disk size with transitive dependencies: "1004KB"
info Number of shared dependencies: 0
✨  Done in 0.22s.
  1. 逐步移除并测试第三方依赖后确认:expo-ads-admob包是错误根源,卸载该包后所有错误消失。进一步查询得知该包已停止维护,推测是版本不兼容引发的模块加载异常。

解决办法

  • 直接卸载停止维护的expo-ads-admob包:
    yarn remove expo-ads-admob
    # 或使用npm
    npm uninstall expo-ads-admob
    
  • 若项目仍需集成广告功能,可替换为Expo官方维护的广告相关库或其他活跃维护的第三方广告解决方案。

内容的提问来源于stack exchange,提问作者Yusuf Numan YILMAZ

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 02:57:28