React Native - pod 安装问题“无法加载此类文件......node_modules/react-native/scripts/react_native_pods”

问题描述 投票:0回答:17

当我有一个 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

react-native cocoapods react-native-ios pod-install
17个回答
51
投票

我运行了

npm audit fix
,它添加了
react_native_pods
文件和
pod install
然后工作了


16
投票

运行 npmauditfix ==> cd ios ==> pod install


16
投票

如果

npm audit fix
不适合您,请尝试以下解决方案。

- sudo gem install cocoapods
- npm i
- cd ios
- pod install

13
投票

也可能是您在运行

yarn
之前忘记运行
npm
/
pod install


4
投票

我遇到了同样的错误,通过将React Native的版本从0.62升级到0.63解决了,它对我有用 由于版本为0.62时,scripts文件夹中不存在react_native_pods文件,当我将RN版本升级到0.63时,出现该文件,在npm install之后,在pod install时可以使用,希望对遇到相同情况的其他人有帮助错误


4
投票

我刚刚在运行

npm install
之前做了
pod install
,它解决了我的问题。


4
投票

确保您已安装 npm 依赖项。

运行以下命令,然后安装 pods。

  1. 安装 npm 包:
yarn install
  1. 然后,删除旧的 pod 缓存:
cd ios && pod deintegrate && rm -rf Podfile.lock
  1. 更新 pod 并启动 ios:
pod install --repo-update && cd .. && react-native run-ios

3
投票

就我而言,我删除了yarn.lock、podfile.lock,再次安装yarn和pod后工作正常


1
投票

为了解决这个问题:我所做的是:

  1. react-native升级:主要升级react-native版本,同时也会升级你的一些ios文件,比如Podfile等。

尝试一下这是否适合您。您还可以创建一个最新的 React Native 项目并使用“超越比较”来比较您的文件/目录,您还需要重命名文件中的某些行。

另请阅读文件中的注释以更好地理解。


1
投票

这对我有用:

cd ios
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install

通过此链接


1
投票

我在 2022 年遇到了这个错误,这是最相关的搜索结果,但没有修复它。所以,如果其他人遇到这个问题,我为此奋斗了几天,最后通过以下方式修复了它:

通过以下方式创建一个全新的目录:expo init new-project,然后复制您的 .js 文件、屏幕和资产等。手动执行此操作,不要复制任何锁定文件或节点模块或其他任何内容。只是您自己创建/接触的文件。然后博览会开始。在您的移动设备/模拟器上加载项目,当项目因缺少模块要求而失败时,单独添加它。重复这个开始-错误-添加,直到构建成功。这是我发现让它发挥作用的唯一方法。


1
投票

就我而言,我从

cocoapods
brew
 安装了 
gem

基于最新的react-native文档,您需要从

gem

安装它

执行以下步骤:

  1. sudo brew uninstall cocoapods
    通过
    brew
  2. 删除 cocoapods 安装
  3. sudo gem uninstall cocoapods
    删除通过
    gem
  4. 安装的 cocoapods

终于

  1. sudo gem install cocoapods
    通过
    gem
  2. 安装最新版本

0
投票

纱线 光盘 吊舱安装

对我有用


0
投票

只需安装,

@react-native-community/cli-platform-ios

在package.json中

然后

yarn install
在你的根中,
cd ios
还有
arch -x86_64 pod install


0
投票

安装 MacOs 14.0 Sonoma 后,我在 mac 上发生了这种情况。我不完全确定问题是什么。两者相对需要的文件

  1. 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

  • 主动支持7.0.8
  • 捆绑器
  • 可可足类

我转到了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
版本上重新开始。


-1
投票

验证您是否有一个node_modules文件夹,我错过了


-1
投票

在 Node_Module->React-Native->Scripts->(在此处添加)中添加react-native.pods.rb 文件

© www.soinside.com 2019 - 2024. All rights reserved.