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

iOS autolinking not working in monorepo #633

Closed
thiagoferolla opened this issue Aug 14, 2019 · 8 comments · Fixed by #768
Closed

iOS autolinking not working in monorepo #633

thiagoferolla opened this issue Aug 14, 2019 · 8 comments · Fixed by #768
Labels
bug Something isn't working

Comments

@thiagoferolla
Copy link

thiagoferolla commented Aug 14, 2019

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?

@thiagoferolla thiagoferolla added the bug Something isn't working label Aug 14, 2019
@birkir
Copy link

birkir commented Aug 16, 2019

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

@thiagoferolla
Copy link
Author

thiagoferolla commented Aug 16, 2019

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

@ryohlan
Copy link

ryohlan commented Aug 17, 2019

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

@gaguirre
Copy link

gaguirre commented Oct 7, 2019

I think this would be fixed in #768

@hindsricardo
Copy link

@ryohlan can you explain why nohoist works please?

@ryohlan
Copy link

ryohlan commented Dec 17, 2019

@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.

@thymikee
Copy link
Member

thymikee commented Dec 17, 2019

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.

@ryohlan
Copy link

ryohlan commented Dec 17, 2019

Yes, it was a workaround temporary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants