-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find module 'react-native/cli' #995
Comments
Is appcenter called from outside of RN project? Can you share the directory structure and where commands are run from? |
I have the same issue. It happens in monorepos that have RN projects inside |
Hi @thymikee, thanks for the quick response. Our React Native package.json file is in a subdirectory called Unfortunately I spoke to soon regarding downgrading the version, that ultimately failed too. I saw that the diff --git a/node_modules/@react-native-community/cli-platform-android/native_modules.gradle b/node_modules/@react-native-community/cli-platform-android/native_modules.gradle
index 8f5dc40..06f6e6c 100644
--- a/node_modules/@react-native-community/cli-platform-android/native_modules.gradle
+++ b/node_modules/@react-native-community/cli-platform-android/native_modules.gradle
@@ -148,10 +148,10 @@ class ReactNativeModules {
* Runs a specified command using Runtime exec() in a specified directory.
* Throws when the command result is empty.
*/
- String getCommandOutput(String[] command) {
+ String getCommandOutput(String[] command, File directory) {
try {
def output = ""
- def cmdProcess = Runtime.getRuntime().exec(command)
+ def cmdProcess = Runtime.getRuntime().exec(command, null, directory)
def bufferedReader = new BufferedReader(new InputStreamReader(cmdProcess.getInputStream()))
def buff = ""
def readBuffer = new StringBuffer()
@@ -194,10 +194,10 @@ class ReactNativeModules {
*/
def cliResolveScript = "console.log(require('react-native/cli').bin);"
String[] nodeCommand = ["node", "-e", cliResolveScript]
- def cliPath = this.getCommandOutput(nodeCommand)
+ def cliPath = this.getCommandOutput(nodeCommand, new File(this.jsAppDir))
String[] reactNativeConfigCommand = ["node", cliPath, "config"]
- def reactNativeConfigOutput = this.getCommandOutput(reactNativeConfigCommand)
+ def reactNativeConfigOutput = this.getCommandOutput(reactNativeConfigCommand, new File(this.jsAppDir))
def json
try { This seems to be working for us so far, though I'm not sure what other side effects this could have. I believe it could potentially solve #804 too, though I haven't looked into that too deeply. Thank you! |
For some reason, this didn't work for us on AppCenter with react-native 0.65 (I think due to 3.0.3 which is broke in this case), we had to do
|
@kyle-ssg are you running AppCenter from a root where there's no node_modules? |
Another workaround for this issue is to put something like this in the pre-build script.
Of course, instead of |
@thymikee Yeah, we have the project in /mobile. Ah, that's a better workaround than staying on the specific version of the CLI, thanks for the suggestion @fstojanac! |
So you could |
Well, that's down to AppCenter, I don't think I'd be able to control that. Haven't checked out Yarn workspace but would rather not like to overcomplicate our current setup for the sake of getting builds working again. |
Can you share a snippet of the appcenter config that runs your builds? |
Unfortunately, I've just realised that the solution of copying mobile to root won't work, app center lets you select build flavours and the package json based on directories |
Hm, why would that prevent copying in the root directory? I've kept location of AppCenter still runs build from the |
Is it fixed? Or any real fix here? I am not able to build it in AppCenter. I am using yarn workspaces |
The workaround here works, but it's tricky in some cases. The real problem is that What we really need is a way to get a path to Gradle configuration or location of MyApplication that we are building. Based on that, we can resolve from there. Anyone has idea how to achieve it? |
Hey, I have already tried the following changes.
The trace: * Where: Script '/Users/runner/runners/2.165.1/work/1/s/PROJECT/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 170 * What went wrong: A problem occurred evaluating script. > internal/modules/cjs/loader.js:638 throw err; ^Error: Cannot find module 'react-native/cli' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at [eval]:1:13 at Script.runInThisContext (vm.js:122:20) at Object.runInThisContext (vm.js:329:38) at Object. ([eval]-wrapper:6:22) at Module._compile (internal/modules/cjs/loader.js:778:30) at evalScript (internal/bootstrap/node.js:590:27) * 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 10s Error: /Users/runner/runners/2.165.1/work/1/s/PROJECT/android/gradlew failed with return code: 1 Can anyone give me a "walkaround" so that the application can be built in the AppCenter? |
@fabienso Android builds have been failing in App Center since 09:30 UTC and the status page still reports |
@WolfyUK Alright do you mean this? The application is now successfully building. The app only needs to be located in the "root directory". Thank you! |
I am also facing this issue after I upgraded my react-native version from 0.60.4 to 0.61.5 and this error I am seeing on app center only. |
update: I got this error fixed in app center by just moving react-native project to root folder. earlier it was in /mobile |
So after fix #1057, who should upgrade what to which version, to make this work in appcenter.ms? |
@Arxcis it looks like so long as you're using @react-native-community/cli-platform-android =>4.4.0 it should fix the issue. I've yet to validate this but looks like this is when the PR was released |
I dont have a reference to @react-native-community/cli-platform-android in my package.json file, but peeking inside node_modules gives me the answer. v3.1.4 $ pwd
node_modules/@react-native-community/cli-platform-android
$ cat package.json
{
"name": "@react-native-community/cli-platform-android",
"version": "3.1.4",
"license": "MIT",
"main": "build/index.js",
"dependencies": {
"@react-native-community/cli-tools": "^3.0.0",
"chalk": "^2.4.2",
"execa": "^1.0.0",
"jetifier": "^1.6.2",
"logkitty": "^0.6.0",
"slash": "^3.0.0",
"xmldoc": "^1.1.2"
},
"publishConfig": {
"access": "public"
},
"files": [
"build",
"native_modules.gradle"
],
"devDependencies": {
"@react-native-community/cli-types": "^3.0.0",
"@types/execa": "^0.9.0",
"@types/fs-extra": "^8.0.0",
"@types/glob": "^7.1.1",
"@types/xmldoc": "^1.1.4"
},
"gitHead": "3158e2e3fa54e3740874af20b2b31eb66df8e0f4"
} grep in package.json in node_modules
|
I can see that |
I solved it by upgrading my project from React Native 0.61 -> 0.62.2, because 0.62.2 uses up-to-date-enough version of the cli:
https://github.com/facebook/react-native/blob/v0.62.2/package.json#L89-L91 Thanks a lot for fixing the bug initially 👍 |
Glad you made it work @Arxcis! |
I had the same issue and solved it this way:
|
you save my life |
very nice solution! you save my life! |
Environment
react-native info output
Description
Hi folks, this issue is very closely related to #406, but I decided to open a new issue for it since it may require a different solution altogether, and that issue is closed.
In short,
@react-native-community/cli-platform-android
is breaking our builds on Appcenter (cc @kinigitbyday #406 (comment) ), using the following versions:The exact failure logged by Appcenter (aka Azure DevOps) is the following:
There is a comment in the affected Gradle file
Sometimes Gradle can be called outside of the JavaScript hierarchy (-p flag)
which seems related. Appcenter calls this with-p app/android
.We have our RN app in a directory called
app/
in our repo, and you can see from the stacktrace that the eval is executed from the root directory of the repo instead of withinapp/
orapp/android
as I would expect.I have tried various versions of
@react-native-community/cli-platform-android
, and it seems that the issue was introduced by this commit which removesnpx
, which was released in3.1.0
: b4b0854We hotfixed this for now by pinning
@react-native-community/cli-platform-android
to the latest version before3.1.0
by adding the following to ourpackage.json
:Hope this helps, let me know if I can help test any solution to this :)
Thank you!
The text was updated successfully, but these errors were encountered: