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

Created Library Does Not Work When Actually Imported In External React Native app #344

Closed
1 of 2 tasks
trevorwhealy opened this issue Dec 9, 2022 · 7 comments
Closed
1 of 2 tasks
Labels
bug Something isn't working

Comments

@trevorwhealy
Copy link

trevorwhealy commented Dec 9, 2022

Description

Created a library like so:

npx create-react-native-library@latest awesome-library

Modified it slightly, re-build it in /example, then yarn start to serve the app.
It built, ran, and worked as expected. No warnings. No errors.

I ran yarn release and it steps through the npm publishing and the Github release creation.
It successfully creates the npm package.

I then ran the following commands to scaffold a new project and install the packages:

npx react-native init AwesomeProject
cd AwesomeProject
yarn
yarn add my-custom-package
cd ios
pod install

I import and use the library I created and once I click on a button to interact it with it, I see this:

Error: The package 'my-custom-package' doesn't seem to be linked. Make sure: 
- You have run 'pod install'
- You rebuilt the app after installing the package
- You are not using Expo Go

I've run pod install - I've re-built the app - and I'm not using Expo Go.

My native module was an extremely simple extension of the original base project.

Not sure where to go from here. Appreciate any tips or suggestions. Thanks

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

Native Module
Swift + Java

Link to repro

No response

Environment

info Fetching system and libraries information...
System:
OS: macOS 13.0
CPU: (10) arm64 Apple M1 Pro
Memory: 82.97 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.0/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v16.18.0/bin/npm
Watchman: 2022.11.28.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

@trevorwhealy trevorwhealy added the bug Something isn't working label Dec 9, 2022
@atlj
Copy link
Collaborator

atlj commented Jan 25, 2023

Hey I've got some questions:

  1. When you ran pod install, did you see your module's name listed?
  2. Does it work on Android?

I suspect the files field of package.json here. The .podspec file might not be published. Could you share this field without exposing sensitive information?

@satya164 satya164 closed this as completed Jul 4, 2023
@trinadhkoya
Copy link

Same here. I could see the same issue.

@atlj
Copy link
Collaborator

atlj commented Sep 11, 2023

@trinadhkoya Could you share more details? A reproducable repository would be awesome so we could take a look at the root cause.

@catmans1
Copy link

@trinadhkoya @trevorwhealy

For my case

  1. Create new project with react-native: 0.73.2
    It will auto link after you run pod install
  2. Older projects
    It won't auto link
    You need to add the code pod 'your module', :path => '../node_modules/your module' below target 'your-project' do and run pod install

@sandeep36butte
Copy link

Iam geeting the same issue with android.
Did you able to resolve this issue?

@JungHsuan
Copy link

It works in an RN App with version 0.73.7, but not in 0.64.4.

@zjkuang
Copy link

zjkuang commented Dec 10, 2024

I recently ran into the same issue and figured out the reason in my case. My project is a monorepo, having a non-standard folder structure. In a standard React Native project, android/ and ios/ are the immediate subfolders in the app's root folder. But in my monorepo project, it's something like ${APP_ROOT}/xxx/yyy/android and ${APP_ROOT}/xxx/yyy/ios. And when I yarn add <my-library> from a sub-package folder like $(APP_ROOT)/zzz, the installation looks good but it crashes at runtime complaining that the library is not linked. The solution is that I have to do yarn add <my-library> from ${APP_ROOT}/xxx/yyy/ in order that it can find the android/ and ios/ folder at its installation spot. Hope this helps in your cases as well.

I am very curious about this since I have also installed many other npm packages and they work perfectly with monorepo and don't require to be installed in exactly the same spot where the android/ and ios/ folders are located. Not sure if in the future this generator can also support monorepo.

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

No branches or pull requests

8 participants