为什么 Pod 依赖管理器没有检测到安装所需的module?

IT技术 javascript reactjs react-native module package
2021-05-14 14:01:42

所以这个问题是我上一个问题的后续: 如何从共享组件文件夹导入不同的应用程序?react / react-native

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

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

我创建了一个使用这个库的加载组件:@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 module(同样是我自己创建的)。

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

在 /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,因为显然我的module没有让项目知道它应该在 ios/Podfile 中安装一些包。

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

我感谢所有的帮助!

2个回答

您是否尝试将 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

这里唯一的变化是源文件的路径

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

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