-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Description
After upgrading our app from React Native 0.68.1 to 0.82.1, we consistently hit a startup runtime error:
txt TypeError: Cannot read property 'setRootNavigation' of undefined
We suspect this is related to circular imports involving barrel files using export * from ....
Simulated structure:
app/navigation/index.ts
app/navigation/navigation-utilities.tsx // exports setRootNavigation
app/navigation/primary-navigator.tsx
app/services/api/api.ts
app/utils/hooks.ts
Simulated index.ts barrel style:
// app/navigation/index.ts
export * from "./navigation-utilities"
export * from "./primary-navigator"
export * from "./root-navigator"
In our module graph, some modules imported by navigation-utilities.tsx eventually reference navigation/index.ts again, creating a circular path.
After the RN upgrade, exports accessed from this barrel chain can become undefined during initialization (e.g. setRootNavigation).
On RN 0.68.1, we did not encounter this undefined runtime issue from the same circular-import pattern.
After upgrading, this now fails at startup.
We want to confirm whether RN 0.82.1 has any global/official mitigation for this class of circular-import-induced undefined errors, beyond manually refactoring imports.
Steps to reproduce
1 Create/prepare an app with:
a barrel file using export * from ...
cross-imports between navigation/utils/services modules
2. Upgrade RN from 0.68.1 to 0.82.1
3. Import startup navigation helpers from barrel file (e.g. from './navigation')
4. Launch app
5. Observe runtime undefined export error at app startup
React Native Version
0.82.1
Affected Platforms
Runtime - iOS
Output of npx @react-native-community/cli info
System:
OS: macOS 15.5
CPU: (12) arm64 Apple M2 Max
Memory: 136.88 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.19.4
path: /usr/local/bin/node
Yarn:
version: 1.22.19
path: /usr/local/bin/yarn
npm:
version: 11.9.0
path: /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8309675
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.16
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 20.0.0
wanted: 20.0.0
react:
installed: 19.2.4
wanted: 19.2.4
react-native:
installed: 0.82.1
wanted: 0.82.1
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
TypeError: Cannot read property 'setRootNavigation' of undefined
at App (app.tsx:69:3)
at react_stack_bottom_frame (ReactFabric-dev.js:15887:29)
at renderWithHooks (ReactFabric-dev.js:3857:40)
at updateFunctionComponent (ReactFabric-dev.js:7289:34)
at beginWork (ReactFabric-dev.js:8541:41)
at runWithFiberInDEV (ReactFabric-dev.js:683:21)
at performUnitOfWork (ReactFabric-dev.js:12218:39)
at workLoopSync (ReactFabric-dev.js:12042:58)
at renderRootSync (ReactFabric-dev.js:12022:23)
at performWorkOnRoot (ReactFabric-dev.js:11585:53)
at performWorkOnRootViaSchedulerTask (ReactFabric-dev.js:3073:24) Error Stack:
at render (CodePush.js:585:16)
MANDATORY Reproducer
https://github.com/UnknowUserLi/reproducer-react-native
Screenshots and Videos
No response