Skip to content

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

Closed
@jerinho

Description

@jerinho

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 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.Type: QuestionIssues that are actually questions and not bug reports.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions