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

Requiring internal react-native modules will stop working #59

Closed
amasad opened this issue Jun 30, 2015 · 5 comments
Closed

Requiring internal react-native modules will stop working #59

amasad opened this issue Jun 30, 2015 · 5 comments

Comments

@amasad
Copy link

amasad commented Jun 30, 2015

react-native uses a module format that is specific to Facebook that relies on a global namespace. We're trying to isolate it from the outside world and use the standard CommonJS and node modules instead. Therefore in the latest react-native version 0.7.0-rc.2 requiring any of the internal modules using their name will be warning and in the future will be an error.

For example require('NativeModules') is now a warning:

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

To depend on NativeModules please use the exported react-native node module:

require('react-native').NativeModules

This issue was originally reported here: facebook/react-native#1808

@mnylen
Copy link

mnylen commented Jul 2, 2015

It seems that the 0.7's updated packager also completely changes how requires should be done.

  • Users of react-native-icons should do require('react-native-icons'). The new packager does not know how to resolve require('FAKIconImage') - it seems to think it as react-native's own module
  • In react-native-icons's code, we should use relative requires: require('./SMXTabBarIconItem.ios') instead of require('SMXTabBarIconItem')
  • We should use the exports on require('react-native') instead of require('NativeModules'), require('View') etc. Like: var {View, NativeModules} = require('react-native')

I started some of this work at https://github.com/mnylen/react-native-icons/tree/0.7-support . Hopefully it helps a bit.

@amasad
Copy link
Author

amasad commented Jul 3, 2015

Yes, good catch. We actually never intended that our non-standard internal module system leak out into the community. It works ok for the company but won't work in the wild; mainly because it's single global namespace. Going forward we want to use node modules standard.

@jeffreywescott
Copy link
Contributor

Why is this closed? AFAICT, this is still a problem in the code:

FAKIconImage.ios.js:

var EdgeInsetsPropType = require('EdgeInsetsPropType');
var NativeMethodsMixin = require('NativeMethodsMixin');
var NativeModules = require('NativeModules');
var PropTypes = require('ReactPropTypes');
var ImageResizeMode = require('ImageResizeMode');
var ImageStylePropTypes = require('ImageStylePropTypes');
var React = require('React');
var ReactNativeViewAttributes = require('ReactNativeViewAttributes');
var StyleSheet = require('StyleSheet');
var StyleSheetPropType = require('StyleSheetPropType');

Am I missing something?

@corymsmith
Copy link
Owner

@jeffreywescott Some of them were fixed and I had closed it incorrectly. Will re-open now. Some of the modules aren't exposed so will have to sort out what to do with those. If you have any thoughts or want to do a PR let me know.

@corymsmith corymsmith reopened this Jul 29, 2015
@jeffreywescott
Copy link
Contributor

See: #71. It's not perfect, but at least things are running in my project on react-native 0.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants