Search code examples
react-nativecocoapodsreact-native-cli

How to make pod install ignore linked lib internal node_modules in react native?


I'm writing an internal UI library here.

I'm using react-native-builder-bob and it works great, I can test my components in the example folder/app and focus on the library development, but when I link the lib into my-app (yarn link && cd ../my-app/ && yarn link my-lib) and run a pod install (cd ios && pod install), the dependencies from the example app end up in my-app podfile.lock like this:

  EXSplashScreen:
    :path: "../node_modules/my-library/example/node_modules/expo-splash-screen/ios"

I'm not ok with it ending up as a direct dependency. And I'm definitely not OK with it breaking my app on launch (my app doesn't use expo) because I don't even invoque any of expo stuff.

So, how can I make sure that I can develop and test things in both projects (example and my-app) without one interfering into each other?

I know I can:

  1. delete example node modules when writing my-app code: but I don't want to do that.
  2. pack the lib with yarn pack, extract the tar contents and link that instead (it doesn't include the example folder)... but it's somehow weird
  3. make the Podfile RN script ignore the example folder.. but I don't know how to do it, and will it work for android?

Edit: About the option 3, it seems that the script that includes sub folders is the react-native-unimodules cocoapods.rb one, it fetches all packages that have unimodules.json


Solution

  • It's not a direct dependency. Unfortunately npm link/yarn link doesn't have the same behavior as a published package. It's also intended for development and not for consuming the package in an app.

    To have the proper behavior, you need to publish the package to a registry and consume it from there. The example isn't uploaded when publishing.

    To test this behavior locally you can:

    • Use something like https://verdaccio.org/ for a local NPM server
    • Run npm pack to create a tgz package that you can install with yarn install /path/to/file