Skip to content

Production chunk loading errors bypass React Error Boundaries and crash the app #1428

Description

@whydidoo

Describe the bug

Production chunk loading failures are converted into fatal React Native exceptions before React.lazy can deliver the rejected import to the nearest Error Boundary.

This affects regular dynamic chunks and Module Federation v2 remotes when an exposed chunk is unavailable.

Actual behavior:

  • The application process terminates.
  • Android reports FATAL EXCEPTION: mqt_v_native with a ChunkLoadError.
  • The Error Boundary never gets a chance to render its fallback.

Expected behavior:

  • The dynamic import rejects.
  • The nearest Error Boundary renders its fallback.
  • The application process remains alive.

Root cause:
Module Federation handles the remote loading rejection by registering a module factory that throws the original ChunkLoadError. The following module execution goes through Re.Pack's guarded webpack_require wrapper, which calls ErrorUtils.reportFatalError. This converts a recoverable asynchronous loading failure into an unconditional fatal exception before it can propagate back to the React.lazy promise.

Proposed solution:
Remove the global guarded webpack_require wrapper and allow module execution errors to propagate to their caller. Uncaught startup errors will still reach React Native's top-level error handling naturally, while dynamic import failures can be handled by promises and React Error Boundaries.

System Info

React Native: 0.86.0
React: 19.2.x
Rspack: 1.6.0
Platforms tested:
- Android Pixel 3a API 33 arm64-v8a emulator
- iOS 17.5 iPhone 15 Pro Simulator
Build mode: production/release
Module Federation: v2

Re.Pack Version

5.2.5 (current main)

Reproduction

https://github.com/callstack/repack/tree/main/apps/tester-federation-v2

Steps to reproduce

  1. Build the tester-federation-v2 host and mini app in production mode.
  2. Serve build/mini-app on port 8082.
  3. Load MiniApp/MiniAppNavigator through React.lazy and wrap it in an Error Boundary.
  4. Remove __federation_expose_MiniAppNavigator.chunk.bundle from the served remote output.
  5. Launch the Release application and open Gallery.

Before the fix:

  • Android terminates with FATAL EXCEPTION: mqt_v_native.
  • iOS also reports the loading failure as fatal.
  • The Error Boundary fallback is not rendered.

Validation after removing the fatal require wrapper:

  • Android with chunk available: remote renders.
  • Android with chunk missing: Error Boundary renders and the PID remains unchanged.
  • iOS with chunk available: remote renders.
  • iOS with chunk missing: Error Boundary renders and the process remains alive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:newNew issue, not reviewed by the team yet.type:bugA bug report.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions