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

Expo Monorepo中双不同SDK版本React Navigation应用Jest测试报错求助

问题:Expo Monorepo下Jest测试触发__fbBatchedBridgeConfig is not set错误

背景

我搭建了一个包含两个不同Expo SDK版本应用的Monorepo,使用React Navigation,并且为所有依赖配置了强制nohoist:

"workspaces": {
    "packages": ["apps/*"],
    "nohoist": ["**/**" ]
  },

应用本身可以正常运行,但Jest测试失败。

报错信息

The above error occurred in the <ForwardRef(NavigationContainerInner)> component:

          at theme (C:\dh\expo-49\apps\playground\node_modules\@react-navigation\native\src\NavigationContainer.tsx:55:5)
          at children (C:\dh\expo-49\apps\playground\src\navigation\InstrumentedNavigationContainer\index.tsx:14:3)
          at App (C:\dh\expo-49\apps\playground\src\App.tsx:10:50)

      Consider adding an error boundary to your tree to customize error handling behavior.
      Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

     Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules

       6 |
       7 | it("should load", async () => {
    >  8 |   render(<App />);

已排查的情况

  • 单独运行每个应用的测试可正常工作
  • 移除其中一个应用后,测试恢复正常
  • 根目录node_modules仅包含lefthook、commitlint以及两个应用的符号链接,其余为空
  • 移除另一个应用中的NavigationContainer组件后,测试也能正常运行

我的问题

还有哪些可能的原因会导致以下报错?

Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules

我的猜测

从报错栈:

at Object.invariant (node_modules/@react-navigation/native/node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:181:3)

推测@react-navigation/native内部嵌套了另一个react-native依赖,这可能是问题的根源。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 15:53:15