Android: latest release broke support custom react-native Root
See original GitHub issueEnvironment
System: OS: Windows 10 CPU: (8) x64 Intel® Core™ i Memory: 15.44 GB Binaries: Node: 12.10.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.19.1 - C:\Users\v\AppData\Roaming\npm\yarn.CMD npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD npmPackages: react: 16.9.0 => 16.9.0 react-native: ^0.61 => 0.61.2
Description
my directory structure is andrapp\ <-- has android ./app , gradlew and so on rn.common\ <-- has package.json index.android.js and ./node_modules
in react-native 60.6 I was able to specify the React native root (in app/build.gradle)
project.ext.react = [
entryFile: "index.android.js",
// whether to bundle JS and assets in debug mode
bundleInDebug: false,
// whether to bundle JS and assets in release mode
bundleInRelease: true,
bundleCommand: "ram-bundle",
enableHermes: false, // clean and rebuild if changing
**root:** "${myRnAppRootDir_abs}"
]
And cli was able to correctly invoke
npx.cmd --quiet react-native config
from within rn.common directory
However since this change https://github.com/react-native-community/cli/commit/5724d29dc979a4b645c620109348a1e5c8c74d03#diff-375026a0607eb034a6fc70cca7d74689
native_modules.gradle
Now invokes npx in ‘default’ directly, not in React’s project root. Which causes
npx.cmd --quiet react-native config
to complain with
error Unrecognized command "config".
info Run "react-native --help" to see a list of all available commands.
Which, then, causes JSON parsing error in native_modules.js
Here is code change in native_modules.js that causes the error on Android
// old code, that was working cmdProcess = Runtime.getRuntime().exec(command, null, root)
// new code that does not work cmdProcess = Runtime.getRuntime().exec(command)
From the design/documentation perspective, it seems that the whole infrastructure for getReactNativeProjectRoot() have been removed, and no alternative/migration documentation has been suggested.
Note also, that react-native 0.61 project template, continues to assert that configuring custom root (where package.json) resides, by specifying root in project.ext.react (in app/build.gradle) – is still a valid and supported option
https://github.com/facebook/react-native/blob/master/template/android/app/build.gradle
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:17 (8 by maintainers)

Top Related StackOverflow Question
@thymikee Please re-open this issue. The problem I reported is not resolved.
I am getting
'[node, -e, console.log(require('react-native/cli').bin);]' in directory 'C:\Users\v\home\devel\myrepo\FRONTEND\a\u1b' command failed.React native 0.62. using most recent CLI release 4.7.0
when executing the build from android studio or when running
gradlew taskIn the u1b , the edirectory where I have my android project (see my directory structure fully described October 16, 2019 comment)The problem still seems to be same (using 4.7.0 release of cli. Tried both on Windows and Linux). The cli is trying to execute java script commands in my Android app directory (u1b), and not in the correct directory which is rn.common
My settings.gradle is the same as when reported the issue 6 months ago
Same build.gradle:
NODE_MODULES environment variable is not set
The problem, clearly the same as before
When settings.gradle invokes
applyNativeModulesSettingsGradle(settings)CLI’snode_modules/@react-native-community/cli-platform-android/native_modules.gradlefails to figure out where my JS directory is (rn.common) – because that capability was removed with CLI release in rn 0.61.To confirm that this is same problem, I modified native_modules.gradle and applied the same solution as @thymikee created before (getting the JS directory from the path of nativ_modules.gradle)
That allowed to build to pass the above mentioned error… But without the above change to CLI code, I simply do not know how to get this to even start the build.
@grabbou I have a monorepo structure set up almost identical to the one you suggested earlier, but the RN CLI doesn’t work properly in root. I don’t want a
react-nativepackage in root, and would like to instead force each sub-folder to specify the RN version in theirpackage.json. However, after doing this the CLI can’t findrun-androidas a command for some reason when running from root.I checked and I’m sure that
react-native, along with all the other packages I need, are correctly hoisted up to root. Thereact-nativecommand even runs, but it doesn’t think thatrun-androidis a valid sub-command. I’m currently runningreact-native run-android --root "./projectName". Is there any more configuration that is needed? To note, this works perfectly fine if I leavereact-nativein the rootpackage.json.Looking through the global
.binforreact-nativeit appears to kick it to mynode_modules/@react-native-community/clipackage after going through thereact-nativeone. There is alsonode_modules/@react-native-community/cli-platform-androidwhich appears to have the commands I am missing, but I’m not sure how the main cli links to it.Structure just to be clear:
where the sub-projects have essentially this as their package.json
and root has ideally nothing in its dependencies (or very little).
Also please feel free to send me to another issue if this isn’t a good place to ask.