realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

@realm/react won't build in react-native 0.81.4 android

Open badaz opened this issue 2 months ago • 9 comments

How frequently does the bug occur?

Always

Description

When trying to build a react-native 0.81.4 project for android with @realm/react 0.20.0 installed, build fails with the following error : /Users/{username}/code/{appname}/node_modules/react-native/sdks/hermes-engine/version.properties (No such file or directory)

I looked at my projet's node_modules/react-native-sdks/hermes-engine location and the file is indeed not there.

However it is present at my project's node_modules/@realm/react/node_modules/react-native/sdks/hermes-enginelocation.

If I copy it from node_modules/@realm/react/node_modules/react-native/sdks/hermes-engine to node_modules/react-native/sdks/hermes-engine the RN project builds fine.

Stacktrace & log output

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/sve/code/countwizapp/android/build.gradle' line: 26

* What went wrong:
A problem occurred evaluating root project 'countwizapp'.
> Failed to apply plugin 'com.facebook.react.rootproject'.
   > A problem occurred configuring project ':app'.
      > Failed to notify project evaluation listener.
         > /Users/sve/code/countwizapp/node_modules/react-native/sdks/hermes-engine/version.properties (No such file or directory)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 9s
error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * Where:
Build file '/Users/sve/code/countwizapp/android/build.gradle' line: 26 * What went wrong:
A problem occurred evaluating root project 'countwizapp'.
> Failed to apply plugin 'com.facebook.react.rootproject'. > A problem occurred configuring project ':app'. > Failed to notify project evaluation listener. > /Users/sve/code/countwizapp/node_modules/react-native/sdks/hermes-engine/version.properties (No such file or directory) * Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org. BUILD FAILED in 9s.
info Run CLI with --verbose flag for more details.

Can you reproduce the bug?

Always

Reproduction Steps

  • Create a bare react-native 0.81.4 project
  • install realm and @realm/react
  • build the project with npx react-native run-android

Version

20.2.0

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android 36

Build environment

debug

Cocoapods version

No response

badaz avatar Oct 18 '25 15:10 badaz

Seems you have a duplicated react-native? What happens if you delete all node_modules recursively and re-install npm install and optionally run npm dedupe?

kraenhansen avatar Oct 19 '25 10:10 kraenhansen

Seems you have a duplicated react-native? What happens if you delete all node_modules recursively and re-install npm install and optionally run npm dedupe?

I'm using yarn 3.6.4. So far I tried rm -rf node_modules && yarn (which I guess is equivalent to what you're suggesting as first step?). react-native 0.81.4 is indeed installed at my project's node_modules/react-native path (which is normal since my package.json requires it) AND react-native 0.82.0 is installed at node_modules/@realm/react/node_modules/react-native path (which I do not know if it is normal as it is an optionalDependency of the @realm/react package). Anyway, I'm not sure the problem comes from having 2 versions installed, my 2 cent is that it tries to do something with the version.properties files of my project's root node_modules/react-native package and that file does not seem to exist in that version of react-native (0.81.4)

EDIT: I tried yarn dedupe but react-native package is still hosted under @realm/react/node_modules

badaz avatar Oct 19 '25 16:10 badaz

react-native is indeed an optional dependency of @realm/react. What changed with the latest version of @realm/react now has a peer dependency on realm@>=20, which might have caused some things to shift around in your package lock.

Can you paste the output of yarn list --pattern react-native and yarn why react-native?

kraenhansen avatar Oct 19 '25 17:10 kraenhansen

yarn why react-native ├─ @realm/react@npm:0.20.0 │ └─ react-native@npm:0.82.0 (via npm:>=0.68) │ ├─ @realm/react@npm:0.20.0 [0ec0b] │ └─ react-native@npm:0.82.0 [a1cf7] (via npm:>=0.68 [a1cf7]) │ └─ countwizapp@workspace:. └─ react-native@npm:0.81.4 [0ec0b] (via npm:0.81.4 [0ec0b])

However there does not seem to be a list command in yarn 3.6.4

badaz avatar Oct 19 '25 20:10 badaz

By the way, despite @realm/react 0.11.0 being incompatible with realm 20, that version was preventing me from building android as well, with the same error. This leads me to think that the problem was already there in the lib (or in my yarn.lock as you suggest)

I'll try deleting my yarn.lock and reinstall deps to see if it changes anything.

badaz avatar Oct 19 '25 22:10 badaz

Ok, I deleted yarn.lock, did yarn install, and am still getting the same build error. yarn why react-native outputs the same as before.

yarn why react-native ├─ @realm/react@npm:0.20.0 │ └─ react-native@npm:0.82.0 (via npm:>=0.68) │ ├─ @realm/react@npm:0.20.0 [0ec0b] │ └─ react-native@npm:0.82.0 [a1cf7] (via npm:>=0.68 [a1cf7]) │ └─ countwizapp@workspace:. └─ react-native@npm:0.81.4 [0ec0b] (via npm:0.81.4 [0ec0b])

badaz avatar Oct 21 '25 08:10 badaz

Same here!

jefmoraes avatar Oct 21 '25 14:10 jefmoraes

Same with RN 0.81.5 which I just upgraded to. The problem seems to come from the fact that @realm/react having react-native as an optionalDependency results in yarn installing its latest version in the dependency's own node_modules folder, then for some reason that I don't have enough knowledge to undestand, the build process seems to be trying to resolve one of this sub node_module's file paths in the root project's node_modules/react-native.

Maybe there is a way to tell yarn to always resolve react-native to a fixed version ? Even for dependencies that require it? I'll try looking into this solution

badaz avatar Oct 23 '25 11:10 badaz

Ok, I found a workaround that is more elegant (and probably more reliable as well) than copying a file as suggested in my OP:

Define a fixed version for react-native in package.json by adding a resolutions config into your project's package.json

{
 	"resolutions": {
    	"react-native": "0.81.5" // change version number according to your project
 	 }
}

Then yarn install won't install any other version of react-native into node_modules/@realm/react/node_modules anymore (in fact there won't be a node_modules folder there anymore) and react-native build will work again.

badaz avatar Oct 23 '25 11:10 badaz