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

How to install or use a package in a library project #22464

Closed
2 of 3 tasks
jerinho opened this issue Nov 30, 2018 · 5 comments
Closed
2 of 3 tasks

How to install or use a package in a library project #22464

jerinho opened this issue Nov 30, 2018 · 5 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.

Comments

@jerinho
Copy link

jerinho commented Nov 30, 2018

Environment (react-native info)

Environment:

  • OS: Windows 10
  • Node: 8.11.4
  • Yarn: 1.9.4
  • npm: 6.4.1
  • Watchman: Not Found
  • Xcode: N/A
  • Android Studio: Not Found

Packages: (wanted => installed)

  • react: 16.3.1 => 16.3.1
  • react-native: 0.55.4 => 0.55.4

Description

In a library project, how actually the proper way to install or simply and directly use a module package?

Reproducible Demo

  1. https://facebook.github.io/react-native/docs/native-modules-setup
  2. https://facebook.github.io/react-native/docs/native-modules-android
  3. By default a library project does not loaded up with any packages including react and react-native. So error Unable to resolve module will come out when you trying to import it in a .js
  4. Let say you want to use module Component. Try to add package yarn add react --save and import it from a .js
  5. react-native run-android from a linked application project directory
  6. I'll jump off the bridge if you never get this error

bundling failed: ambiguous resolution: module C:\Users\USER\Desktop\test\index.js tries to require react, but there are several files providing this module. You can delete or fix them:

*C:\Users\USER\AppData\Local\Yarn\Data\link\react-native-mylibrary\node_modules\react\package.json
*C:\Users\USER\Desktop\test\node_modules\react\package.json

What have you (me) tried ???

Please. I know the why I found this error. But that's not the answer I wanna know. I'm just looking for how to install and use a package in linked external project. That's all. Nothing more and nothing less 😄

@react-native-bot
Copy link
Collaborator

It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the issue still exists.

The "⏪Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

@jerinho
Copy link
Author

jerinho commented Nov 30, 2018

It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the issue still exists.

The "⏪Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

sorry. i thought the issues section is also for backward support. seems like i'm wrong. actually, this issue has nothing to do with react native version of the application project. because the error occurs in the library project, which i can't run react-native command from, high possibility is because it is a library project. the only info i can provide about the library project is as below. it was generated from latest version of react-native-create-library

  "peerDependencies": {
    "react-native": "^0.41.2",
    "react-native-windows": "0.41.0-rc.1"
  }

it's ok. no hard feeling. i'll do as per your request. thank you for your reply

@jerinho
Copy link
Author

jerinho commented Nov 30, 2018

finally managed to compile with latest version. but my apologize i cannot edit my post. because metro bundler does not lists all the project directories like when i compile with version as i state in the post, like this ...

Looking for JS files in
C:\Users\USER\Desktop\test
C:\Users\USER\AppData\Local\Yarn\Data\link\react-native-mylibrary

... followed by error Unable to resolve module react-native-mylibrary produced by the import part of code.

since this error has nothing to do with the issue, i think the best is to not include it into the post. if someone want to open new issue for this, it's your call.

@hramos hramos added the Type: Question Issues that are actually questions and not bug reports. label Nov 30, 2018
@react-native-bot
Copy link
Collaborator

We are using GitHub issues exclusively to track bugs in React Native. GitHub may not be the ideal place to ask a question, but you can try asking over on Stack Overflow, or on Reactiflux. You may also use discuss.reactjs.org/ to discuss best practices.

@react-native-bot react-native-bot added the Ran Commands One of our bots successfully processed a command. label Nov 30, 2018
@jerinho
Copy link
Author

jerinho commented Dec 2, 2018

I've put my answer here ... including some complaints about how bad react native team do their job 😆

@facebook facebook locked as resolved and limited conversation to collaborators Nov 30, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Nov 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.
Projects
None yet
Development

No branches or pull requests

3 participants