当我有一个 React Native 项目时......当我运行
pod install
时,它给了我以下错误
Invalid `Podfile` file: cannot load such file -- /myPath/node_modules/react-native/scripts/react_native_pods
这是我的 podfile
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '10.0'
target 'xs' do
config = use_native_modules!
use_react_native!(:path => config["reactNativePath"])
target 'xsTests' do
inherit! :complete
# Pods for testing
end
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
use_flipper!
post_install do |installer|
flipper_post_install(installer)
end
end
target 'xs-tvOS' do
# Pods for xs-tvOS
target 'xs-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end
我检查过,位置
react_native_pods
中没有名为myPath/node_modules/react-native/scripts/
的文件。
我想知道它是否与 npm install
没有生成正确的文件有关......但是我将节点升级到最新版本,然后运行 npm install
我运行了
npm audit fix
,它添加了react_native_pods
文件和pod install
然后工作了
运行 npmauditfix ==> cd ios ==> pod install
如果
npm audit fix
不适合您,请尝试以下解决方案。
- sudo gem install cocoapods
- npm i
- cd ios
- pod install
也可能是您在运行
yarn
之前忘记运行 npm
/ pod install
。
我遇到了同样的错误,通过将React Native的版本从0.62升级到0.63解决了,它对我有用 由于版本为0.62时,scripts文件夹中不存在react_native_pods文件,当我将RN版本升级到0.63时,出现该文件,在npm install之后,在pod install时可以使用,希望对遇到相同情况的其他人有帮助错误
我刚刚在运行
npm install
之前做了 pod install
,它解决了我的问题。
确保您已安装 npm 依赖项。
运行以下命令,然后安装 pods。
yarn install
cd ios && pod deintegrate && rm -rf Podfile.lock
pod install --repo-update && cd .. && react-native run-ios
就我而言,我删除了yarn.lock、podfile.lock,再次安装yarn和pod后工作正常
为了解决这个问题:我所做的是:
尝试一下这是否适合您。您还可以创建一个最新的 React Native 项目并使用“超越比较”来比较您的文件/目录,您还需要重命名文件中的某些行。
另请阅读文件中的注释以更好地理解。
我在 2022 年遇到了这个错误,这是最相关的搜索结果,但没有修复它。所以,如果其他人遇到这个问题,我为此奋斗了几天,最后通过以下方式修复了它:
通过以下方式创建一个全新的目录:expo init new-project,然后复制您的 .js 文件、屏幕和资产等。手动执行此操作,不要复制任何锁定文件或节点模块或其他任何内容。只是您自己创建/接触的文件。然后博览会开始。在您的移动设备/模拟器上加载项目,当项目因缺少模块要求而失败时,单独添加它。重复这个开始-错误-添加,直到构建成功。这是我发现让它发挥作用的唯一方法。
就我而言,我从
cocoapods
和 brew
安装了
gem
基于最新的react-native文档,您需要从
gem
安装它
执行以下步骤:
sudo brew uninstall cocoapods
通过 brew
sudo gem uninstall cocoapods
删除通过 gem
终于
sudo gem install cocoapods
通过 gem
纱线 光盘 吊舱安装
对我有用
只需安装,
@react-native-community/cli-platform-ios
在package.json中
然后
yarn install
在你的根中,cd ios
还有 arch -x86_64 pod install
安装 MacOs 14.0 Sonoma 后,我在 mac 上发生了这种情况。我不完全确定问题是什么。两者相对需要的文件
require_relative '../node_modules/react-native/scripts/react_native_pods'
或
2.
Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip
存在,我可以期待它们,但 cocoapods 要么无法理解它们,要么找不到它们。
最后我不得不用
rvm
彻底删除 rvm implode
并卸载 rvm。干净地重新安装它并使用与我的Gemfile
ruby ">= 2.6.10"
中列出的版本兼容的Ruby版本
我选择使用
2.7.8
,因为它是目前最高的2.x.y
版本。
之后我必须重新安装以下 gems
我转到了react-native项目的根目录并做了
bundle install
然后进入
ios
并运行 pod install。
这一切都在一个新创建的反应原生项目中
npx react-native@latest init AwesomeProject
"react": "18.2.0",
"react-native": "0.72.5",
一切似乎都运转良好。我的理论是更新 MacO 后。它用默认安装中的二进制文件替换了我的一些 rvm 路径二进制文件,从而破坏了一些东西。或者,我的 ruby 版本在
3.x
上是错误/混乱的,我需要在兼容的 2.x.y
版本上重新开始。
验证您是否有一个node_modules文件夹,我错过了
在 Node_Module->React-Native->Scripts->(在此处添加)中添加react-native.pods.rb 文件