Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autolink doesn't work for libraries which depend on other components with native module #1347

Open
chj-damon opened this issue Jan 12, 2021 · 8 comments
Labels
no-stale-bot This issue cannot be marked as stale by stale bot question Further information is requested

Comments

@chj-damon
Copy link

Ask your Question

I build a react-native-library that relies on many other dependencies, like react-native-svgreact-native-image-picker etc. all these dependencies have native modules.
library
|- react-native-svg
|- react-native-image-picker
|- rn-fetch-blob
|- react-native-reanimated

Now In one project I install my library and run pod install under ios folder, it seems that autolink won't link these native modules from my library dependencies.

what should I do to make it work? I don't want to put all these dependencies in peerDependencies to ask the user to install them manually.

@chj-damon chj-damon added the question Further information is requested label Jan 12, 2021
@brentvatne
Copy link
Contributor

there are some cases where autolinking of transitive dependencies could be very useful, but it is not supported at the moment in react-native-cli's autolinking and, even if it were, i would not recommend using it for these specific cases.

  1. the libraries you referred to above are likely to be used directly by a developer outside of the context of your library too, and you developers should include any dependencies that they directly import in their app in their dependencies
  2. if your library installed these dependencies and users also installed them in their package.json, it would be very easy for the versions to go out of sync and lead to multiple versions of the packages being installed. eg: react-native-svg could be under node_modules/react-native-svg and node_modules/your-lib/node_modules/react-native-svg. while this works fine for pure js projects, it does not work for native libraries. you can only link one version of the library, and you will have two versions of the js code.

@chj-damon
Copy link
Author

I understand that. But I also what to know what the best way to solve this problem is. If my library is built upon many dependencies that have native modules, I don't want my users to install these dependencies themselves, that is very inconvenient I think.

@brentvatne
Copy link
Contributor

@chj-damon - i agree it's not always ideal! if you have some proposal for how to do it better, then i'd love to hear it! for now, explaining to users that they need to install these other packages is the best you can do. for example: https://reactnavigation.org/docs/getting-started#installing-dependencies-into-a-bare-react-native-project

@chj-damon
Copy link
Author

I made an example project under my library project, which I want to use the native module:
library
|- android
|- ios
|- src
|- example

How can I make it work? I tried to config react-native.config.js:

module.exports = {
  assets: ['./assets/fonts'],
  dependencies: {
    'myLib': {
      root: '../android',
    },
  },
};

it doesn't work.

@chj-damon
Copy link
Author

is there any manual about how to build a library that contains native modules, and an example project to test it?

@AlenToma
Copy link

AlenToma commented Jul 1, 2022

I am having the same issue. We should be able to configure those in the library.
Like running a script or something too tell the cli to autolink those library.

I cannot think of a reason why you have not solved this yet.
There should not be any negative reason to include this as we already add peerDependencies and even if for some reason that it could cause problem if this specified globally, we should be able to run some script or configuration that specify which library should be included in autolink.

@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Nov 26, 2022
@github-actions github-actions bot closed this as completed Dec 4, 2022
@thymikee thymikee reopened this Dec 5, 2022
@github-actions github-actions bot removed the stale label Dec 6, 2022
@TMisiukiewicz TMisiukiewicz added the no-stale-bot This issue cannot be marked as stale by stale bot label Dec 6, 2022
@meypod
Copy link

meypod commented Jul 4, 2023

I feel like this is relevant for mono repos as well (I'm using yarn berry)
what I'm trying to do is to put all dependencies inside a package (app) and use them across platform (mobile, web)
without being able to autolink them, I have to install A LOT with same versions from my "app" package inside each repo, which isn't really convenient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-stale-bot This issue cannot be marked as stale by stale bot question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants