upgrade-support icon indicating copy to clipboard operation
upgrade-support copied to clipboard

Cannot read property 'ReactCurrentOwner' of undefined, js engine: hermes

Open tapz opened this issue 10 months ago • 4 comments

Environment

I have this in my package.json, but still RN one again can't do even a simple task without errors:

⚠️ react-native depends on @react-native-community/cli for cli commands. To fix update your package.json to include:

  "devDependencies": {
    "@react-native-community/cli": "latest",
  }

With npx:

System:
  OS: macOS 15.2
  CPU: (12) arm64 Apple M2 Max
  Memory: 1.17 GB / 96.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.18.0
    path: ~/.nvm/versions/node/v20.18.0/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v20.18.0/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.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:
    API Levels:
      - "34"
      - "35"
    Build Tools:
      - 34.0.0
      - 35.0.0
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12700392
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 23.0.1
    path: /opt/homebrew/opt/openjdk/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.1.3
    wanted: latest
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.77.0
    wanted: 0.77.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Things I’ve done to figure out my issue

Upgrading version

0.77

Description

When upgrading from 0.75 to 0.77 I started getting this runtime error:

TypeError: Cannot read property 'ReactCurrentOwner' of undefined, js engine: hermes	
TypeError: Cannot read property 'default' of undefined, js engine: hermes	
TypeError: Cannot read property 'ReactCurrentOwner' of undefined, js engine: hermes	
TypeError: Cannot read property 'default' of undefined, js engine: hermes	

With new arch enabled I got this error:

AndroidRuntime	 java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app/my.app.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'com.facebook.react.interfaces.fabric.ReactSurface com.facebook.react.ReactHost.createSurface(android.content.Context, java.lang.String, android.os.Bundle)' on a null object reference	
AndroidRuntime	 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4129)	
AndroidRuntime	 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4316)	
AndroidRuntime	 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)	
AndroidRuntime	 	at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)	
AndroidRuntime	 	at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)	
AndroidRuntime	 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)	
AndroidRuntime	 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2719)	
AndroidRuntime	 	at android.os.Handler.dispatchMessage(Handler.java:109)	
AndroidRuntime	 	at android.os.Looper.loopOnce(Looper.java:232)	
AndroidRuntime	 	at android.os.Looper.loop(Looper.java:317)	
AndroidRuntime	 	at android.app.ActivityThread.main(ActivityThread.java:8787)	
AndroidRuntime	 	at java.lang.reflect.Method.invoke(Native Method)	
AndroidRuntime	 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)	
AndroidRuntime	 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:871)	
AndroidRuntime	 Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'com.facebook.react.interfaces.fabric.ReactSurface com.facebook.react.ReactHost.createSurface(android.content.Context, java.lang.String, android.os.Bundle)' on a null object reference	
AndroidRuntime	 	at com.facebook.react.ReactDelegate.loadApp(ReactDelegate.java:293)	
AndroidRuntime	 	at com.facebook.react.ReactActivityDelegate.loadApp(ReactActivityDelegate.java:155)	
AndroidRuntime	 	at com.facebook.react.ReactActivityDelegate.lambda$onCreate$0(ReactActivityDelegate.java:149)	
AndroidRuntime	 	at com.facebook.react.ReactActivityDelegate.$r8$lambda$HPdXfLmAU1y4Wc1XbwAHziPP2WA(Unknown Source:0)	
AndroidRuntime	 	at com.facebook.react.ReactActivityDelegate$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)	
AndroidRuntime	 	at com.facebook.systrace.Systrace.traceSection(Systrace.kt:39)	
AndroidRuntime	 	at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:117)	
AndroidRuntime	 	at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:47)	
AndroidRuntime	 	at my.app.MainActivity.onCreate(MainActivity.java:172)	
AndroidRuntime	 	at android.app.Activity.performCreate(Activity.java:9019)	
AndroidRuntime	 	at android.app.Activity.performCreate(Activity.java:8997)	
AndroidRuntime	 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1528)	
AndroidRuntime	 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4111)	
AndroidRuntime	 	... 13 more	

With both new arch and hermes disabled:

TypeError: undefined is not an object (evaluating 'ReactSharedInternals.ReactCurrentOwner')	
TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[2], "../Renderer/shims/ReactNative").default')	
TypeError: undefined is not an object (evaluating 'ReactSharedInternals.ReactCurrentOwner')	
TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[2], "../Renderer/shims/ReactNative").default')	

Really hate this when every single time when I update RN the build breaks completely. Even when following the upgrade helper instructions. I really don't understand what the RN developers are doing when they can't keep comptability. Probably millions of developers just waste enormous amount of time just to fight with RN. Let's hope someone releases a better alternative than this total hack of a library.

Reproducible demo

tapz avatar Jan 30 '25 10:01 tapz

have you found any solution? i am facing same issue

alihamza1729 avatar Feb 03 '25 12:02 alihamza1729

same issue facing

mokashi21 avatar Feb 07 '25 12:02 mokashi21

Same issue, any solutions?

guzeradimaz avatar Feb 09 '25 23:02 guzeradimaz

So, I just downgrade react version from 19.0.0 to 18.3.1

yarn remove react yarn add [email protected] and then try to build app

upgrade tool helps me -> https://react-native-community.github.io/upgrade-helper/?from=0.76.0&to=0.77.0

my react native version is 0.77.0

guzeradimaz avatar Feb 10 '25 00:02 guzeradimaz

In case it's helpful to anyone, I found I was on an old version of why-did-you-render that didn't support React 19, so I just removed it (for now)

abejfehr avatar Jul 16 '25 21:07 abejfehr

@abejfehr That fixed the issue for me as well. Thank you!

timmyjose avatar Nov 12 '25 07:11 timmyjose

I'm still facing this issue but this time comes from https://github.com/Shopify/react-native-skia on old arch / RN 0.78

fadi-quader-mox avatar Nov 14 '25 03:11 fadi-quader-mox