Skip to content

Commit

Permalink
Add a check in InitializeCore.js that PlatformConstants native module…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fromcelticpark authored and grabbou committed Oct 13, 2017
1 parent afdd0d5 commit dd63cbf
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Libraries/Core/InitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 {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 = 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
Expand Down

0 comments on commit dd63cbf

Please sign in to comment.