react-native-reanimated-carousel: Reanimated global.__reanimatedWorkletInit is not a function

Describe the bug

When i try use library with Expo, the follow message shows

TypeError: global.__reanimatedWorkletInit is not a function. (In 'global.__reanimatedWorkletInit(_f)', 'global.__reanimatedWorkletInit' is undefined)

If i put the code

global.__reanimatedWorkletInit = () => {};

on '…/lib/commonjs/utils/dealWithAnimation.js works correctly

To Reproduce Steps to reproduce the behavior:

  1. Install library and try use
  2. See error

Screenshots image

Versions:

  • expo: ~45.0.0
  • react: v17.0.2
  • react-native: v0.68.1
  • react-native-reanimated: v^2.8.0
  • react-native-reanimated-carousel: v^2.3.10
  • react-native-gesture-handler: v~2.2.0

Smartphone:

  • Device: iPhoneXR
  • OS: iOS 15.4

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 33 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I add global.__reanimatedWorkletInit = () => { }; to \node_modules\react-native-reanimated\src\Animated.js and the issue gone

import * as reanimated1 from './reanimated1';
import ReanimatedComponents from './reanimated2/component';

global.__reanimatedWorkletInit = () => { }; // <--- add this line

const Animated = {
  // components
  ...ReanimatedComponents,
  createAnimatedComponent,
  // configuration
  addWhitelistedNativeProps,
  addWhitelistedUIProps,
  // reanimated 1
  ...reanimated1,
};

Same here!

I have the same problem

Same problem here. All debugging instructions are ineffective

I released it in 2.6.0.

This error is triggered by this PR, And there is related issue.

In version 2.7.0+, __reanimatedWorkletInit is deleted, so i added this code to my index file.

+ if (!('__reanimatedWorkletInit' in global)) {
+     Object.assign(global, { __reanimatedWorkletInit: () => {} });
+ }

export type { TCarouselProps, ICarouselInstance } from './types';
import Carousel from './Carousel';

export default Carousel;

I think this should work with different versions of reanimated. And this problem has been happening for too long. Sorry. I will reopen this issue if there is any problem. 🍺

Im working with Expo SDK and it require react-native-reanimated 2.8.0. I know downgrade to Reanimated 2.6.0 the issues fix, but i want somehelp with react-native-reanimated 2.8.0. Pls fix it. Thanks you. @dohooo

I patched reanimated package 2.8.0 (by patch-package) and it’s works for me:

diff --git a/node_modules/react-native-reanimated/lib/reanimated2/core.js b/node_modules/react-native-reanimated/lib/reanimated2/core.js
index 284915e..b266740 100644
--- a/node_modules/react-native-reanimated/lib/reanimated2/core.js
+++ b/node_modules/react-native-reanimated/lib/reanimated2/core.js
@@ -2,6 +2,9 @@
 import NativeReanimatedModule from './NativeReanimated';
 import { Platform } from 'react-native';
 import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
+
+global.__reanimatedWorkletInit = () => { };
+
 if (global._setGlobalConsole === undefined) {
     // it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1
     global._setGlobalConsole = () => {

patch did not work for me. Removing all calls to global.__reanimatedWorkletInit() in node_modules/react-native-reanimated-carousel/lib/commonjs/* using patch-package did the trick for now until a proper fix is made.

@thanhtrung07 Maybe I’m stating the obvious but modifying a package in node_modules is not a very stable solution to any problem. The ‘fix’ will break when building to production, and it will not be added to your commits.

Having the same issue since update of expo SDK 45 Your fix is not working on my side

I patched reanimated package 2.8.0 (by patch-package) and it’s works for me:

diff --git a/node_modules/react-native-reanimated/lib/reanimated2/core.js b/node_modules/react-native-reanimated/lib/reanimated2/core.js
index 284915e..b266740 100644
--- a/node_modules/react-native-reanimated/lib/reanimated2/core.js
+++ b/node_modules/react-native-reanimated/lib/reanimated2/core.js
@@ -2,6 +2,9 @@
 import NativeReanimatedModule from './NativeReanimated';
 import { Platform } from 'react-native';
 import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
+
+global.__reanimatedWorkletInit = () => { };
+
 if (global._setGlobalConsole === undefined) {
     // it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1
     global._setGlobalConsole = () => {

this library is working fine on expo but it wasn’t working for me with nextjs, however adding this somewhere high up the hierarchy (e.g. App.tsx) fixed it:

global.__reanimatedWorkletInit = () => {}

I have the same problem. Reducing or upgrading the ‘react-native-reanimated’ version has no effect

same here. I tried using import 'react-native-reanimated' as suggested in: https://stackoverflow.com/questions/70750047/typeerror-global-reanimatedworkletinit-is-not-a-function-in-global-reani with no effect.