【问题标题】:Why doesn't the Pod dependency manager detect the necessary modules for installation?为什么 Pod 依赖管理器没有检测到安装所需的模块?
【发布时间】:2020-01-13 22:20:14
【问题描述】:

所以这个问题是对我之前的问题的跟进: How can different apps import from a shared components folder? react / react-native

所以我创建了自己的 npm 模块,我在其中存储了所有组件。这些组件可以被任意数量的应用程序使用。因为我将使这些组件高度可重用。

但我还是偶然发现了一个问题。

我创建了一个使用这个库的加载组件:@react-native-community/masked-view。该库需要在 /ios/Podfile 中安装依赖项。 首先我在其中一个 react-native 项目中创建了这个组件。

yarn add @react-native-community/masked-view
..
success Saved 1 new dependency.

cd ios/
pod install
..
Installing RNCMaskedView (0.1.6)
Pod installation complete! There are 33 dependencies from the Podfile and 31 total pods installed.

'

然后我运行了我的代码,加载组件就可以工作了。现在我想将它添加到 NPM 模块(同样,我自己创建的),它将包含我的所有组件。

所以我进入 /my-awesome-99-components/,它有自己的 package.json,因为它是一个模块,我将在我正在处理的每个项目中导入它。

在 /my-awesome-99-components/

yarn add react react-native @react-native-community/masked-view
..
success Saved 1 new dependency.

// Created Loading.js - this is the loading component

yarn publish
..

在 /react-native-project-1/

yarn add my-awesome-99-components
..
Done in 3.17s.

cd ios/
Pod install
..

这就是问题出现的地方。现在 Podfile 不会安装 RNCMaskedView 因为显然我的模块没有让项目知道它应该在 ios/Podfile 中安装一些包。

有谁知道为什么会发生这种情况,最好的解决方案是什么?

感谢所有帮助!

【问题讨论】:

    标签: javascript reactjs react-native module package


    【解决方案1】:

    您是否尝试将 podspec 文件添加到您的存储库?

    您可以从 masked-view 包中修改 podspec 文件,如

    require 'json'
    
    package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
    
    Pod::Spec.new do |s|
      s.name         = "RNCMaskedView"
      s.version      = package['version']
      s.summary      = package['description']
    
      s.authors      = package['author']
      s.platforms    = { :ios => "9.0", :tvos => "9.0" }
    
      s.source       = { :git => "https://github.com/react-native-community/react-native-masked-view.git", :tag => "v#{s.version}" }
      s.source_files  = "node_modules/@react-native-community/masked-view/ios/**/*.{h,m}"
    
      s.dependency 'React'
    end
    

    这里只改变源文件的路径

    【讨论】:

    【解决方案2】:

    这是 Podfile 和整体 React Native 从依赖项与依赖项链接的典型问题。 react-navigation-stack@react-native-community/masked-view 有同样的问题

    唯一的解决方案是将 peerDependency 标记为@react-native-community/masked-view,以便使用您的库的用户知道可能需要另一个依赖项,并单独安装它。这个answer 可能会更好地回答您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      相关资源
      最近更新 更多