You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title says. If React Native is star-imported, e.g.
import * as RN from 'react-native';
then the app shows a "Native module cannot be null" redbox on startup and fails to load. Similarly, Jest tests fail with the same error.
Reproduction
I can reproduce this by taking the starting project from react-native init AwesomeProject and adding the following line to index.ios.js.
import * as RN from 'react-native';
The app then shows the following error on startup:
Likewise, npm test fails with the following error:
FAIL __tests__/index.ios.js
● Test suite failed to run
Invariant Violation: Native module cannot be null.
at invariant (node_modules/fbjs/lib/invariant.js:44:15)
at Linking.NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:32:1)
at new Linking (node_modules/react-native/Libraries/Linking/Linking.js:119:141)
at Object.<anonymous> (node_modules/react-native/Libraries/Linking/Linking.js:191:16)
at Object.get Linking [as Linking] (node_modules/react-native/Libraries/react-native/react-native.js:91:22)
at _interopRequireWildcard (index.ios.js:14:233)
at Object.<anonymous> (index.ios.js:14:4)
Here attached is a project demonstrating this, which was produced by taking the react-native init project and adding the single line given above.
This seems to occur because Babel transforms the above code into
var _reactNative = require("react-native");
var RN = _interopRequireWildcard(_reactNative);
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};
if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key))
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
}
I'm guessing that those property accesses are triggering initialization on some of the native modules, which is failing if they're not linked. Worth noting is that using import RN from 'react-native' instead works fine.
I dunno how to fix it. I just talk about things.
Additional Information
React Native version: 0.40.0
Platform: iOS, and in tests. I haven't tried running on Android, but I would guess it's there too.
Operating System: OSX 10.11.6
The text was updated successfully, but these errors were encountered:
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
Description
As the title says. If React Native is star-imported, e.g.
then the app shows a "Native module cannot be null" redbox on startup and fails to load. Similarly, Jest tests fail with the same error.
Reproduction
I can reproduce this by taking the starting project from
react-native init AwesomeProject
and adding the following line toindex.ios.js
.The app then shows the following error on startup:
Likewise,
npm test
fails with the following error:Here attached is a project demonstrating this, which was produced by taking the
react-native init
project and adding the single line given above.ImportRepro.zip
Solution
This seems to occur because Babel transforms the above code into
I'm guessing that those property accesses are triggering initialization on some of the native modules, which is failing if they're not linked. Worth noting is that using
import RN from 'react-native'
instead works fine.I dunno how to fix it. I just talk about things.
Additional Information
The text was updated successfully, but these errors were encountered: