-
Notifications
You must be signed in to change notification settings - Fork 887
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
How to solve "Cannot find module 'react-native/cli" correctly? #2289
Comments
hey @AlexanderEggers, as of my knowledge there's no unfortunately. I'll try to find a way to set this path correctly. |
hey @AlexanderEggers, can you please try setting diff --git a/my_wraper/android/gradlew b/my_wraper/android/gradlew
old mode 100644
new mode 100755
diff --git a/my_wraper/android/settings.gradle b/my_wraper/android/settings.gradle
index 9694a74..f3259bf 100644
--- a/my_wraper/android/settings.gradle
+++ b/my_wraper/android/settings.gradle
@@ -1,4 +1,5 @@
rootProject.name = 'AwesomeProject'
+rootProject.projectDir = new File(rootProject.projectDir, "../reactnativemodule")
apply from: file("../reactnativemodule/node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../reactnativemodule/node_modules/@react-native/gradle-plugin')
|
@szymonrybczak Thanks for your suggestion but I'm not certain if that is what would make sense in this case. The base Android project still needs to be compiled and is indeed the root project. The missing option is to define the RN root project so that the native modules gradle file resolves correctly. Something like injecting a custom path as part of this line |
@szymonrybczak I have open a PR with some suggestions which could fix the mentioned issue (#2341). |
There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. |
Ask your Question
Edit: I just noticed #1600 already discusses the issue. I must have missed that when creating this issue. Feel free to close my issue, I will keep that open in case that helps solve the underlying issue.
I have the following use case in my project setup:
Essentially I want to use react-native (0.73) in an existing Android project without having to actually update its structure or anything related to that. Currently the react-native android plugin in gradle is already providing quite a bit of options to define paths to its options, so my look like this:
The Android project contains those plugin defintions but nothing else except actually consuming the rn-module.
Of course the project based gradle contains the react-native gradle plugin defintion and the root-project plugin usage.
The rn-module contains the actual gradle dependencies:
Additionally the rn-module also contains
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
. This is to ensure that the generated package list file is created, but just for the module, not for the android base project to avoid mixing these projects too much. Because the node_modules and everything around that is not part of the android base project, running native_modules.gradle actually fails with a gradle exception which relates to a missing node module.Caused by: java.lang.Exception: node:internal/modules/cjs/loader:1137 throw err; ^Error: Cannot find module 'react-native/cli'Require stack:- /Users/alex.eggers/Documents/Projects/RNAndroid/[eval] at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15) at Module._load (node:internal/modules/cjs/loader:975:27) at Module.require (node:internal/modules/cjs/loader:1225:19) at require (node:internal/modules/helpers:177:18) at [eval]:1:87 at Script.runInThisContext (node:vm:122:12) at Object.runInThisContext (node:vm:298:38) at node:internal/process/execution:82:21 at [eval]-wrapper:6:24 at runScript (node:internal/process/execution:81:62) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/alex.eggers/Documents/Projects/RNAndroid/[eval]' ]}Node.js v18.19.0
The fix that I've applied is:
So my question is if there is a solution out there which avoids having that patch in place or is that simply something the current CLI is not supporting in its setup?
The text was updated successfully, but these errors were encountered: