Cli: iOS autolinking not working in monorepo

Created on 14 Aug 2019  路  8Comments  路  Source: react-native-community/cli

Environment

System:
OS: macOS 10.15
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 255.71 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
Android SDK:
API Levels: 23, 25, 26, 27, 28
Build Tools: 23.0.1, 25.0.1, 25.0.2, 26.0.1, 26.0.2, 27.0.3, 28.0.0, 28.0.1, 28.0.2, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.5429.30.34.5452501
Xcode: 11.0/11M382q - /usr/bin/xcodebuild
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-create-library: 3.1.2

Description

I created a project with react native 0.60.4 in a monorepo (using yarn workspaces). The project has de following structure:

project
  |
  |- node_modules
  |- packages
     |-react-native-app
       |- ios
       |- android
       |- src

I followed the react native docs (https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) on how to configure autolinking with custom roots, so I changed the paths in my Podfile to:

require_relative '../../../node_modules/@react-native-community/cli-platform-ios/native_modules'

use_native_modules!("../../..")

The problem is that when I run pod install it install only the react-native default dependencies and doesn't identify any fo the 3rd party libraries added to the app.

Is the podfile configuration right? Should I run any other command to make it work?

bug

Most helpful comment

use nohoist.

in react-native-app/package.json

  "workspaces": {
    "nohoist": [
      "@react-native-community",
      "react-native",
      "react-native/!(react)/**",
      "react-native-gesture-handler"
    ]
  },

My monorepo repository https://github.com/ryohlan/monorepo/blob/master/mobile/package.json

All 8 comments

require_relative '../../../../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../../../../node_modules/@react-native-community/cli-platform-ios/native_modules'

That actualyy didn't work. node_modules are in ../../../node_modules so when running pod install with the path suggested I got the error:

Invalid Podfile file: cannot load such file

use nohoist.

in react-native-app/package.json

  "workspaces": {
    "nohoist": [
      "@react-native-community",
      "react-native",
      "react-native/!(react)/**",
      "react-native-gesture-handler"
    ]
  },

My monorepo repository https://github.com/ryohlan/monorepo/blob/master/mobile/package.json

I think this would be fixed in #768

@ryohlan can you explain why nohoist works please?

@hindsricardo
Because 'require_relative' in Podfile refers '@react-native-community/cli-platform-ios/native_modules' as relative path.
In default, yarn workspace installs all libraries under the root package's node_modules, not child package.
So, Podfile fails to find @react-native-community.
This is a reason why monorepo fails installing.

As using 'nohoist', selected libraries are installed child package's node_modules, not root package.
By doing this, Podfile can find it.

In a monorepo you likely _want_ to hoist libs to dedup them, so default Yarn behavior is good. You can (and should) update the relative path in the Podfile, to point wherever your RN node module is.

Yes, it was a workaround temporary.

Was this page helpful?
0 / 5 - 0 ratings