diff --git a/__tests__/versionCheck.test.js b/__tests__/versionCheck.test.js new file mode 100644 index 00000000000..1bafe957568 --- /dev/null +++ b/__tests__/versionCheck.test.js @@ -0,0 +1,21 @@ +const { + checkVersion, +} = require('../src/reanimated2/platform-specific/checkVersion'); +const { version: packageVersion } = require('../package.json'); + +describe('desc', () => { + beforeAll(() => { + global._REANIMATED_VERSION_CPP = packageVersion; + jest.spyOn(console, 'error'); + }); + + afterAll(() => { + delete global._REANIMATED_VERSION_CPP; + console.error.mockRestore(); + }); + + it('checks version successfully', () => { + checkVersion(); + expect(console.error).not.toHaveBeenCalled(); + }); +}); diff --git a/src/reanimated2/NativeReanimated/NativeReanimated.ts b/src/reanimated2/NativeReanimated/NativeReanimated.ts index 6916460baa8..faf1403f75c 100644 --- a/src/reanimated2/NativeReanimated/NativeReanimated.ts +++ b/src/reanimated2/NativeReanimated/NativeReanimated.ts @@ -23,6 +23,15 @@ export class NativeReanimated { this.InnerNativeModule = global.__reanimatedModuleProxy; this.native = native; if (native) { + if (this.InnerNativeModule === undefined) { + console.error( + `[Reanimated] The native part of Reanimated doesn't seem to be initialized. This could be caused by\n\ + - not rebuilding the app after installing or upgrading Reanimated\n\ + - trying to run Reanimated on an unsupported platform\n\ + - running in a brownfield app without manually initializing the native library` + ); + return; + } checkVersion(); } } diff --git a/src/reanimated2/platform-specific/checkVersion.ts b/src/reanimated2/platform-specific/checkVersion.ts index 1b64bb62d62..45d6db73bc6 100644 --- a/src/reanimated2/platform-specific/checkVersion.ts +++ b/src/reanimated2/platform-specific/checkVersion.ts @@ -1,4 +1,9 @@ -import { version as jsVersion } from '../../../package.json'; +/** + * We hardcode the version of Reanimated here in order to compare it + * with the version used to build the native part of the library in runtime. + * Remember to keep this in sync with the version declared in `package.json` + */ +const jsVersion = '3.0.0-rc.10'; /** * Checks that native and js versions of reanimated match.