Reputation: 881
So this question is a follow up to my previous question: How can different apps import from a shared components folder? react / react-native
So I've created my own npm module which I store all my components in. These components can be used by as many apps as I like. Because I will be making those components highly reusable.
But I still have stumbled upon a problem.
I have created a loading component which uses this library: @react-native-community/masked-view. This library needs to install a dependency inside /ios/Podfile. First I created this component inside one of the react-native projects.
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.
'
So then I ran my code, and the Loading component works. Now I want to add this to the NPM module (that, again, I created myself) which will contain all my components.
So I go into /my-awesome-99-components/ which has its own package.json since it is a module which I will import in each project I'm working on.
In /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
..
In /react-native-project-1/
yarn add my-awesome-99-components
..
Done in 3.17s.
cd ios/
Pod install
..
This is where the problem comes up. Now the Podfile won't install the RNCMaskedView because apparently my module doesn't let the project know that it should install some packages inside the ios/Podfile.
Does anyone know why this happens, and what would be the best solution for this?
I appreciate all the help!
Upvotes: 6
Views: 2873
Reputation: 2673
Have you tried adding a podspec file to your repo?
You can modify the podspec file from the masked-view package like
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
only change here would be the path of the source files
Upvotes: 1
Reputation: 150
This is a typical issue with Podfile and overall React Native linking from dependencies with dependencies. react-navigation-stack
had the same issue with @react-native-community/masked-view
.
The only solution is to mark as @react-native-community/masked-view
a peerDependency, so the user using your library knows that there might be another dependency needed, and install it separately. Your problem might be better answered by this answer.
Upvotes: 0