Skip to content

Metro resolver recursion when separated uniwind instances are installed #353

@eliotgevers

Description

@eliotgevers

What happened?

When running a dev build via bun expo run:ios, the app crashes with an infinite recursion in Uniwind’s Metro resolver. The error is a NativeModules stack overflow. This does not happen in Expo Go (same repo, same code).

Error signature:

[runtime not ready]: RangeError: Maximum call stack size exceeded (native stack depth)
get NativeModules
get NativeModules
...

Findings / root cause hypothesis:

  • Uniwind rewrites require(\"react-native\")uniwind/components for most modules.
  • Inside uniwind/components, many getters call require(\"react-native\") again (to access NativeModules, etc).
  • If Uniwind fails to detect that the origin is inside Uniwind, it rewrites again → infinite loop.
  • Guard currently uses:
    context.originModulePath.startsWith(cachedInternalBasePath)
  • Under Bun, the path looks like:
    .../node_modules/.bun/uniwind@1.2.7/node_modules/uniwind/dist/module/components/...
    but cachedInternalBasePath is:
    .../node_modules/uniwind/dist/module
  • That mismatch makes isInternal false → rewrite loop.

Suggested fix:

  • Normalize paths with realpathSync (or equivalent) for both cachedInternalBasePath and originModulePath, or
  • Use a package-boundary check (e.g. /node_modules/uniwind/) instead of a raw startsWith on a non-normalized path.

Steps to Reproduce

  1. Clone the repo below
  2. bun install
  3. bun expo run:ios
  4. Launch the dev build (crash occurs on startup)

Note: Expo Go does not crash.

Snack or Repository Link (Optional)

https://github.com/eliotgevers/uniwind-heroui-bun-repro

Uniwind version

1.2.7

React Native Version

0.81.5

Platforms

iOS

Expo

Yes

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions