cli
cli copied to clipboard
Error: Cannot find module 'react-native/cli'
bug: Error: Cannot find module 'react-native/cli' when move android dir outer react-native js project use relative path
same problem as 0.68.2, when move android dir outer react-native js project use relative path
[email protected]: version "0.68.2" resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.68.2.tgz#07547cd31bb9335a7fa4135cfbdc24e067142585" integrity sha512-qNMz+mdIirCEmlrhapAtAG+SWVx6MAiSfCbFNhfHqiqu1xw1OKXdzIrjaBEPihRC2pcORCoCHduHGQe/Pz9Yuw== dependencies: "@jest/create-cache-key-function" "^27.0.1" "@react-native-community/cli" "^7.0.3" "@react-native-community/cli-platform-android" "^7.0.1" "@react-native-community/cli-platform-ios" "^7.0.1"~/Desktop/android ❯ ./gradlew clean --info 2.7.4 00:49:44 Initialized native services in: /Users/kr.mao/.gradle/native Initialized jansi services in: /Users/kr.mao/.gradle/native The client will now receive all logging from the daemon (pid: 10648). The daemon log file: /Users/kr.mao/.gradle/daemon/7.3.3/daemon-10648.out.log Starting 28th build in daemon [uptime: 1 hrs 38 mins 9.32 secs, performance: 100%, non-heap usage: 39% of 512 MiB] Using 8 worker leases. Now considering [/Users/kr.mao/Desktop/android, /Users/kr.mao/Workspace/rn_addtoapp_bridge/example/node_modules/react-native-gradle-plugin, /Users/kr.mao/Workspace/rn_addtoapp_bridge/example/android] as hierarchies to watch Watching the file system is configured to be enabled if available File system watching is active Starting Build :settings:reactNativeBusinessRootRelativePath=../../Workspace/rn_addtoapp_bridge/example :ReactNative:Unexpected empty result of running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command. :ReactNative:Running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command failed. FAILURE: Build failed with an exception. * Where: Script '/Users/kr.mao/Workspace/rn_addtoapp_bridge/example/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 213 * What went wrong: A problem occurred evaluating script. > node:internal/modules/cjs/loader:936 throw err; ^Error: Cannot find module 'react-native/cli'Require stack:- /Users/kr.mao/Desktop/android/[eval] at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at [eval]:1:87 at Script.runInThisContext (node:vm:129:12) at Object.runInThisContext (node:vm:305:38) at node:internal/process/execution:75:19 at [eval]-wrapper:6:22 at evalScript (node:internal/process/execution:74:60) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/kr.mao/Desktop/android/[eval]' ]} * Try: > Run with --stacktrace option to get the stack trace. > Run with --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org
I found the key in native_modules.gradle
ext.applyNativeModulesSettingsGradle = { DefaultSettings defaultSettings, String root = null ->
if (root != null) {
logger.warn("${ReactNativeModules.LOG_PREFIX}Passing custom root is deprecated. CLI detects root automatically now.");
logger.warn("${ReactNativeModules.LOG_PREFIX}Please remove second argument to `applyNativeModulesSettingsGradle`.");
}
autoModules.addReactNativeModuleProjects(defaultSettings)
}
ext.applyNativeModulesAppBuildGradle = { Project project, String root = null ->
if (root != null) {
logger.warn("${ReactNativeModules.LOG_PREFIX}Passing custom root is deprecated. CLI detects root automatically now");
logger.warn("${ReactNativeModules.LOG_PREFIX}Please remove second argument to `applyNativeModulesAppBuildGradle`.");
}
same project with different dir got different output
~/Workspace/rn_addtoapp_bridge/example/android master !1 ❯ pwd 7s 2.7.4 02:24:05
/Users/kr.mao/Workspace/rn_addtoapp_bridge/example/android
~/Workspace/rn_addtoapp_bridge/example/android master !1 ❯ node /Users/kr.mao/Desktop/android/../../Workspace/rn_addtoapp_bridge/example/node_modules/@react-native-community/cli/build/bin.js config
{
"root": "/Users/kr.mao/Workspace/rn_addtoapp_bridge/example",
"reactNativePath": "/Users/kr.mao/Workspace/rn_addtoapp_bridge/example/node_modules/react-native",
"dependencies": {
"rn_addtoapp_bridge": {
"root": "/Users/kr.mao/Workspace/rn_addtoapp_bridge",
"name": "rn_addtoapp_bridge",
"platforms": {
"ios": {
~/Desktop/android ❯ pwd ✘ INT 2.7.4 02:37:10
/Users/kr.mao/Desktop/android
~/Desktop/android ❯ node /Users/kr.mao/Desktop/android/../../Workspace/rn_addtoapp_bridge/example/node_modules/@react-native-community/cli/build/bin.js config 2.7.4 02:37:12
~/Desktop/android ❯ 2.7.4 02:37:13
this will force people use parent dir node_modules, can't custom clipath now. integrate rn to exsting app, we really need a different js dir, not must be a parent dir. thanks. can some way resolve this? now I can only with patch-package Originally posted by @krmao in https://github.com/react-native-community/cli/issues/1600#issuecomment-1229240714
react-native info
~/Workspace/rn_addtoapp_bridge/example master ❯ npx react-native info 2.7.4 10:22:20
info Fetching system and libraries information...
System:
OS: macOS 12.4
CPU: (8) arm64 Apple M1 Pro
Memory: 557.05 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.14.0/bin/yarn
npm: 8.15.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
Watchman: 2022.07.04.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /Users/kr.mao/.rvm/gems/ruby-2.7.4/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
Build Tools: 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3, 29.0.0, 29.0.0, 29.0.1, 29.0.2, 29.0.3, 30.0.0, 30.0.0, 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0, 33.0.0
System Images: android-21 | Intel x86 Atom_64, android-22 | Google APIs Intel x86 Atom, android-28 | China version of Wear OS Intel x86 Atom, android-29 | ARM 64 v8a, android-30 | Google APIs Intel x86 Atom, android-31 | ARM 64 v8a, android-Tiramisu | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8609683
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.16 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.68.2 => 0.68.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found