react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Bridge & Packager] Module resolution issues after 0.7.0-rc.2 upgrade.

Open dhrrgn opened this issue 11 years ago • 31 comments

I wanted to test 0.7.0-rc.2, so I made the update and tried running my application. Now, everytime I stop the packager, and it restarts, I get this error:

2015-06-30 11:10:55.714 [error][tid:main][RCTModuleData.m:119] SMXTabBarManager is returning nil for it's methodQueue, which is not permitted. You must either return a pre-initialized queue, or @synthesize the methodQueue to let the bridge create a queue for you.

(I am not sure that is related to the module resolution, so, I can move that to its own issue if needed)

However, that "goes away" after a second, and it replaced by module resolution errors. I am using a few 3rd-party modules, which worked fine in 0.6.0. However, now I am getting Unable to resolve module errors. This even happens when trying to require react-timer-mixin.

Furthermore, when it actually can find and import the module, that module's code then can't resolve core RN modules. Example:

Unable to resolve module NativeModules from [project_path]/node_modules/react-native-keyboardevents/KeyboardEvents.ios.js

dhrrgn avatar Jun 30 '15 15:06 dhrrgn

@tadeuzagallo - the error re: methodQueue seems like something you would know about :smile:

@amasad - NativeModules seems packager related :smile_cat:

brentvatne avatar Jun 30 '15 16:06 brentvatne

@brentvatne @amasad I just want to clarify that it is not only NativeModules, I just used that error as an example. Here is another error:

Unable to resolve module react-timer-mixin from [project_path]/App/Components/TimeAgo.js

dhrrgn avatar Jun 30 '15 16:06 dhrrgn

@dhrrgn - try npm i react-timer-mixin --save and restart the packager, see if it fixes that issue for you. This happened I believe in 0.6.0 (don't quote me on it) and unfortunately I believe it wasn't covered in the changelog.

brentvatne avatar Jun 30 '15 16:06 brentvatne

@brentvatne Ok, so I have made some progress here. I had to re-install all of my dependencies, and things started working much better. Basically I just re-ran npm i [package] --save for all of them. I also had to install react-timer-mixin (which is not mentioned in the docs...it just says to use it).

One of my dependencies is still having an issue, but I think that is an issue with that package. Basically, that package can't find any of the RN modules (I had to fork it and remove the RN peerDependency to even get it to install with the RC anyways...here is my fork of that https://github.com/tackk/react-native-icons).

I will note: I am still getting the red screen with the methodQueue error (this does not happen with a "fresh" install, and I have tried restarting the packager, xcode, simulator, etc), but it only flashes then goes away.

dhrrgn avatar Jun 30 '15 17:06 dhrrgn

Another side note BTW: Even though the packager says that it can't find all of these modules, the app runs perfectly fine with no red screens (other than the methodQueue one mentioned above).

Unable to resolve module EdgeInsetsPropType from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module NativeMethodsMixin from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module NativeModules from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ReactPropTypes from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ImageResizeMode from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ImageStylePropTypes from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module React from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ReactNativeViewAttributes from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module StyleSheet from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module StyleSheetPropType from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module createReactNativeComponentClass from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module flattenStyle from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module insetsDiffer from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module invariant from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module merge from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module warning from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module deepDiffer from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module EdgeInsetsPropType from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module NativeMethodsMixin from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module NativeModules from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ReactPropTypes from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ImageResizeMode from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ImageStylePropTypes from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module React from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module ReactNativeViewAttributes from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module StyleSheet from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module StyleSheetPropType from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module createReactNativeComponentClass from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module flattenStyle from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module insetsDiffer from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module invariant from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module merge from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module warning from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js
Unable to resolve module deepDiffer from [project_path]/node_modules/react-native-icons/FAKIconImage.ios.js

dhrrgn avatar Jun 30 '15 17:06 dhrrgn

I also had to install react-timer-mixin (which is not mentioned in the docs...it just says to use it).

Can you send a pull request for this please? I can merge right away

One of my dependencies is still having an issue, but I think that is an issue with that package. Basically, that package can't find any of the RN modules (I had to fork it and remove the RN peerDependency to even get it to install with the RC anyways...here is my fork of that https://github.com/tackk/react-native-icons).

What was the issue you were having with peerDependencies? I believe it should let you install anyways, but it will warn you if it you don't satisfy the dependency.

I will note: I am still getting the red screen with the methodQueue error (this does not happen with a "fresh" install, and I have tried restarting the packager, xcode, simulator, etc), but it only flashes then goes away.

Strange one there for @tadeuzagallo

brentvatne avatar Jun 30 '15 17:06 brentvatne

@brentvatne I will get a PR in there in a minute, here is the error regarding the peerDep:

pm ERR! Darwin 14.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "update" "--save" "react-native"
npm ERR! node v0.12.4
npm ERR! npm  v2.10.1
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package react-native does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants react-native@>=0.5.0 <1.0.0

Edit: I have this sneaking suspicion I may be doing something completely wrong, and all of this is because I am being stupid ha.

dhrrgn avatar Jun 30 '15 17:06 dhrrgn

@brentvatne https://github.com/facebook/react-native/pull/1811

dhrrgn avatar Jun 30 '15 17:06 dhrrgn

I also had to install react-timer-mixin (which is not mentioned in the docs...it just says to use it).

Yes, I'm sure it was installed somewhere before, it was never bundled with react-native. Thanks for the PR.

NativeModules is an internal module, it was never intended to be required by external modules. To reference something in react-native they should have it as a peerDependency and do require('react-native').NativeModules. It still works because I didn't want it to be a breaking change, but will break in the future. I'll open issues on the packages you mentioned.

here is the error regarding the peerDep:

This just says that the package expects a certain version of react-native to be installed and what you have installed doesn't satisfy the condition: react-native@>=0.5.0 <1.0.0

amasad avatar Jun 30 '15 18:06 amasad

I opened an issue for react-native-icons and luckily @ide fixed react-native-keyboardevents https://github.com/johanneslumpe/react-native-keyboardevents/commit/5e571914903c83c7faf1316c26fa6f94f50d7a19

Is there a way to reach out to more library authors and inform them of this change?

amasad avatar Jun 30 '15 18:06 amasad

@amasad Thanks for the clarification there. I would say a mention in the changelog under "Breaking Changes" would be sufficient, as that would have removed much of my confusion on this issue.

We can close this issue now if we like. I am still not sure about the methodQueue error though, so we can possibly keep it open for that, or I can create a separate issue for that.

dhrrgn avatar Jun 30 '15 18:06 dhrrgn

@dhrrgn I didn't know hotlinking into private modules was that prevalent but it's not breaking yet. Although it's a warning and not an error

@vjeux Can you update the changelog to mention that hotlinking into private modules is no longer allowed?

amasad avatar Jun 30 '15 18:06 amasad

@amasad It is prevalent because that is how the docs show us how to do it. See the iOS Calendar Module Example as well as in the Styles Section of the Native Components docs. This is may be worth its own section on that page (or at least a prominent note).

dhrrgn avatar Jun 30 '15 19:06 dhrrgn

@amasad @brentvatne I have figured out that the methodQueue error only happens when I get the warnings about the unresolved modules, so this is somehow connected to that.

Also, there is a larger issue here in that many of the "internal" modules commonly used by native components / modules are not yet available via the react-native public interface.

I updated react-native-video the best I could, and still, there are a good number of unexposed modules being used (therefor, a lot of warnings). https://github.com/brentvatne/react-native-video/pull/71

dhrrgn avatar Jun 30 '15 20:06 dhrrgn

@amasad, @brentvatne, @dhrrgn I did some bisecting and commit 4ac5c7e19e4d3da642270e8129631e17ad25b755 seems to cause issues at least with react-native-icons (error message: Requiring unknown module FAKIconImage. If you are sure the module is there, try restarting the packager).

In the previous commit 0898bb427fd629037b82023e63eac97c37d1c3b9 a simple require('FAKIconImage') still works.

mnylen avatar Jul 02 '15 18:07 mnylen

@mnylen - we're seeing a similar error with a require('cssVar') inside the react-native-navbar package. this error exists with both react-native 0.7 rc1 (which does not include https://github.com/facebook/react-native/commit/4ac5c7e19e4d3da642270e8129631e17ad25b755) and rc2 (which does).

screen shot 2015-07-02 at 12 38 36 pm

mattmo avatar Jul 02 '15 19:07 mattmo

Yeah, 4ac5c7e is not the real problem. It's 2d4055e513fea0cb36873447d67e64229a187aad

I was able to pinpoint the exact location:

redirectRequire in packager/react-packager/src/DependencyResolver/Package.js seems to return FAKIconImage when doing require('FAKIconImage')

If I change the lines 47-50 from this:

if (!browser || typeof browser !== 'object') {
    return name;
}

to this:

if (!browser || typeof browser !== 'object') {
    if (name === "FAKIconImage") { return "react-native-icons"; }
   return name;
}

I'm able to require('FAKIconImage') correctly. This is obviously not a real solution.

mnylen avatar Jul 02 '15 20:07 mnylen

What code is trying to reqiure FAKIconImage? Is it code within react-native-icons or your own app code? If it's the latter, requiring react-native-icons is the right solution.

ide avatar Jul 02 '15 20:07 ide

HEUREKA. So instead of FAKIconImage require I should do this in my own code:

const FAKIconImage = require('react-native-icons')
  • The package.json for react-native-icons defines FAKIconImage.ios.js as the main script for the package
  • Previously the react-native-packager has resolved FAKIconImage correctly to react-native-icons package

mnylen avatar Jul 02 '15 20:07 mnylen

@ide, my own. It was the react-native-icon's documented way of using it. So, it seems this might be a react-native-icons issue (and probably the same in other 3rd party libraries).

Though, might be a good idea to document that packager can't resolve requires like that anymore from app code.

mnylen avatar Jul 02 '15 20:07 mnylen