![](/img/trans.png)
[英]React-Native Native Module 'canOverrideAnExistingModule() Error'
[英]react-native integration with existing native project getting error Cannot find module 'react-native/cli'
我正在尝试将最新的 RN 项目集成到本机项目中。 这两个项目都在不同的目录中,这意味着我的本机项目不存在于预定义的 ios 文件夹中。
版本:
RN Native:0.63.3 @react-native-community/cli:4.13.0 使用 yarn global add @react-native-community/cli 全局安装。
我收到错误消息,指出未找到 react-native-community package。
我的 pod 文件如下所述:
require_relative '../AwesomeProject/node_modules/react-native/scripts/react_native_pods'
require_relative '../AwesomeProject/node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '10.0'
use_frameworks!
def main_pods
config = use_native_modules!
use_react_native!(:path => config["reactNativePath"])
end
target 'NativeFramework' do
main_pods
end
target 'Example' do
main_pods
end
错误:
[!] Invalid `Podfile` file: [!] /usr/local/bin/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'react-native/cli'
你说你已经用 Yarn 安装了@react-native-community/cli
。 错误消息表明这可能不适合您。 这并不奇怪,因为您的 Podfile 说它可以在您项目的子目录中找到。
为什么不使用npm
安装,看看会发生什么?
cd
到 AwesomeProjectnpm i @react-native-community/cli
或者,更改您的 Podfile,使其指向全局位置。
出于某种奇怪的原因,它与 yarn install 一起工作,然后进行 pod install
react-native": "0.68.2" java11 Apple M1 Pro
经过这么多时间,我发现问题是 android-project 目录必须在 react-native-project 目录中!
rvm reset rvm install 2.7.2 rvm get stable --auto-dotfiles
删除 settings.gradle 中的 dependencyResolutionManagement,添加到 allprojects.repositories 到 root build.gradle
# try sudo ln -s "$(which node)" /usr/local/bin/node open -a /Applications/Android\ Studio.app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.