mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 18:25:06 +00:00
Add a check in InitializeCore.js that PlatformConstants native module is present
Summary: In some enviroments PlatformConstants native module may not be presented in a project, which results in a call to undefined property and a RedBox Reviewed By: javache Differential Revision: D5960879 fbshipit-source-id: 80aecbe2f2a61cb410abd5f0dce8ba855e166991
This commit is contained in:
parent
346af557c3
commit
96f23e7416
@ -116,21 +116,24 @@ if (!global.__fbDisableExceptionsManager) {
|
||||
ErrorUtils.setGlobalHandler(handleError);
|
||||
}
|
||||
|
||||
const formatVersion = version =>
|
||||
`${version.major}.${version.minor}.${version.patch}` +
|
||||
(version.prerelease !== null ? `-${version.prerelease}` : '');
|
||||
const {PlatformConstants} = require('NativeModules');
|
||||
if (PlatformConstants) {
|
||||
const formatVersion = version =>
|
||||
`${version.major}.${version.minor}.${version.patch}` +
|
||||
(version.prerelease !== null ? `-${version.prerelease}` : '');
|
||||
|
||||
const ReactNativeVersion = require('ReactNativeVersion');
|
||||
const nativeVersion = require('NativeModules').PlatformConstants.reactNativeVersion;
|
||||
if (ReactNativeVersion.version.major !== nativeVersion.major ||
|
||||
ReactNativeVersion.version.minor !== nativeVersion.minor) {
|
||||
throw new Error(
|
||||
`React Native version mismatch.\n\nJavaScript version: ${formatVersion(ReactNativeVersion.version)}\n` +
|
||||
`Native version: ${formatVersion(nativeVersion)}\n\n` +
|
||||
'Make sure that you have rebuilt the native code. If the problem persists ' +
|
||||
'try clearing the watchman and packager caches with `watchman watch-del-all ' +
|
||||
'&& react-native start --reset-cache`.'
|
||||
);
|
||||
const ReactNativeVersion = require('ReactNativeVersion');
|
||||
const nativeVersion = PlatformConstants.reactNativeVersion;
|
||||
if (ReactNativeVersion.version.major !== nativeVersion.major ||
|
||||
ReactNativeVersion.version.minor !== nativeVersion.minor) {
|
||||
throw new Error(
|
||||
`React Native version mismatch.\n\nJavaScript version: ${formatVersion(ReactNativeVersion.version)}\n` +
|
||||
`Native version: ${formatVersion(nativeVersion)}\n\n` +
|
||||
'Make sure that you have rebuilt the native code. If the problem persists ' +
|
||||
'try clearing the watchman and packager caches with `watchman watch-del-all ' +
|
||||
'&& react-native start --reset-cache`.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up collections
|
||||
|
Loading…
x
Reference in New Issue
Block a user