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

[RN 0.49] React inside app's local package either doesn't exist, or multiple copies loaded #16320

Closed
fungilation opened this issue Oct 11, 2017 · 4 comments
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@fungilation
Copy link

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

$ react-native info

Environment:
  OS:  macOS Sierra 10.12.6
  Node:  8.6.0
  Yarn:  1.2.0
  npm:  5.3.0
  Watchman:  4.9.0
  Xcode:  Xcode 9.0 Build version 9A235
  Android Studio:  Not Found

Packages: (wanted => installed)
  react: 16.0.0-beta.5 => 16.0.0-beta.5
  react-native: 0.49.3 => 0.49.3

Steps to Reproduce

  1. Upgraded RN from 0.48 to 0.49
  2. My local forked package of react-native-webview-bridge broke, see below under Actual Behavior

Expected Behavior

react not needed as a dependency in a local package (my fork of https://github.com/alinz/react-native-webview-bridge), nor is my hack fix needed to import directly from main app's node_modules/, and bundling goes through without error when react-native run-ios is run.

Actual Behavior

From yarn outdated of my local package:

react-native-webview-bridge       0.33.0        exotic        exotic dependencies ../react-native-webview-bridge-RN0.40

With RN up to 0.48, my app's inclusion and import of react-native-webview-bridge like above works without issue. The package has no dependency itself of react.

Since upgrading to RN 0.49.3, this bundling error occurs on running react-native run-ios:

Unable to resolve module `react` from [package index]: Module does not exist in the module map

screenshot 2017-10-10 17 11 21

Then I added react as a dependency in package.json, like so:

  "devDependencies": {
    "react": "16.0.0-beta.5"
  },

Bundler will then error on Invariant violation: ... You may have multiple copies of React loaded.

screenshot 2017-10-10 17 21 23

screenshot 2017-10-10 17 21 37

A bit of a damned if I do, damned if I don't on getting react dependency in inside the package? Either none found, or there's 2 copies.

I made a hack fix as workaround around both errors, by replacing all instances inside the package of

var React = require('react');

with

var React = require('[HOMEDIR]/Documents/code/[PROJECT]/node_modules/react');

I hardcoded the react path to the exact copy of react my main app (PROJECT) imports, which avoids not able to resolve module react. I have to alter a sub module inside the package too: react-native-webview-bridge-RN0.40/node_modules/create-react-class/index.js which imports React, which makes this doubly hacky and prone to overwritten.

If there's a less dirty workaround, I'm all ears.


This is a repost of facebook/metro#74 as this involves React not being resolved and maybe a RN issue?

@Rinyeo
Copy link

Rinyeo commented Oct 15, 2017

I also meet this problem ,My local version RN 0.49.3, import 'react-native-splash-screen' module and run react-native run-ios command then bundling error.

@ssomnoremac
Copy link

ssomnoremac commented Oct 16, 2017

I had a similar problem as well. I had hot-reloading on when I changed RN versions. Got packager errors all over the place. Just turned off hot-reloading in iOS simulator and got back to normal.

@stale
Copy link

stale bot commented Dec 15, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 15, 2017
@fungilation
Copy link
Author

I figured it out. It was due to ../react-native-webview-bridge-RN0.40 being a symlink. Resolved by moving the folder to the same physical location instead of a symlink.

It'd still be nice if RN supports symlinks properly.

@facebook facebook locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants