Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reanimated global.__reanimatedWorkletInit is not a function #182

Closed
jhorranisbr opened this issue May 9, 2022 · 33 comments
Closed

Reanimated global.__reanimatedWorkletInit is not a function #182

jhorranisbr opened this issue May 9, 2022 · 33 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed needs review The issue has been solved, Wait for confirmation.

Comments

@jhorranisbr
Copy link

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
@jhorranisbr jhorranisbr added the bug Something isn't working label May 9, 2022
@valinagacevschi
Copy link

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.

@dohooo
Copy link
Owner

dohooo commented May 9, 2022

wcandillon/react-native-redash#395 (comment)
Is any help with this problem?

@jhorranisbr
Copy link
Author

wcandillon/react-native-redash#395 (comment) Is any help with this problem?

same with react-native-gesture-handler: ^2.4.2

I see that mention before this issue.

I will wait fix this
Crash when updating to react-native-reanimated 2.7.0 #159

@tengjingyao
Copy link

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

@dohooo dohooo added the help wanted Extra attention is needed label May 11, 2022
@slytter
Copy link

slytter commented May 11, 2022

I have the same problem

@SimonDamberg
Copy link

Same here!

@murat0
Copy link

murat0 commented May 12, 2022

Same here

@owen12ab
Copy link

Same here. Any workaround?

@louisholley
Copy link

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 = () => {}

@mcatal
Copy link

mcatal commented May 12, 2022

I have the same problem with EXPO, RN .68.2

@dohooo
Copy link
Owner

dohooo commented May 15, 2022

Are there any help with this line?

global.__reanimatedWorkletInit = () => {};

@dohooo dohooo added the needs review The issue has been solved, Wait for confirmation. label May 15, 2022
@mcatal
Copy link

mcatal commented May 15, 2022

Are there any help with this line?

global.__reanimatedWorkletInit = () => {};

it work for me.

If i put the code

global.__reanimatedWorkletInit = () => {};

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

Expo 45
Rn .68.2

@dohooo
Copy link
Owner

dohooo commented May 15, 2022

Are there any help with this line?

global.__reanimatedWorkletInit = () => {};

it work for me.

If i put the code

global.__reanimatedWorkletInit = () => {};

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

Expo 45 Rn .68.2

If put it to your project will what happens?

@mcatal
Copy link

mcatal commented May 15, 2022

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

this problem was gone, and it works correctly. Solved for me.

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

@ssarnot
Copy link

ssarnot commented May 16, 2022

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 = () => {

@Simon-Bru
Copy link

Simon-Bru commented May 17, 2022

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

@yosukapro
Copy link

Same problem here. All debugging instructions are ineffective

@rdhox
Copy link

rdhox commented May 19, 2022

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 = () => {

I'm not able to make it work with your solution with expo SDK 45.
The call to the function __reanimatedWorkletInit in this library seems to be generated by the compilation with typescript in the file dealWithAnimation.js.

@thanhtrung07
Copy link

thanhtrung07 commented May 19, 2022

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,
};

@slytter
Copy link

slytter commented May 20, 2022

@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.

@AlexanderLindkjaer
Copy link

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.

@mmdevcodes
Copy link

Since this error only happens on Expo SDK 45 I had to downgrade using expo upgrade 44. It worked but is obviously not recommended.

@anhquan291
Copy link

Facing the same issue on Reanimated 2.8.0. Any update guys? Thanks

@kbqdev
Copy link

kbqdev commented May 26, 2022

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

ishrak-imam pushed a commit to litentry/archived-litentry-mobile-app that referenced this issue Jun 1, 2022
ishrak-imam pushed a commit to litentry/archived-litentry-mobile-app that referenced this issue Jun 2, 2022
* Fixing the react-native-reanimated-carousel error
dohooo/react-native-reanimated-carousel#182

* Adding active account state
@dohooo dohooo closed this as completed in 591f0d8 Jun 4, 2022
@dohooo
Copy link
Owner

dohooo commented Jun 4, 2022

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. 🍺

@shop-fluencer
Copy link

I get still this error, I cleared my cache, I added this code but nothing helps

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. 🍺

@dohooo
Copy link
Owner

dohooo commented Jun 5, 2022

I get still this error, I cleared my cache, I added this code but nothing helps

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. 🍺

You don't need to add this code, just upgrade the carousel version to 2.6.0

@shop-fluencer
Copy link

You don't need to add this code, just upgrade the carousel version to 2.6.0

I updated it, but not working, anyone else has this problem ? I have to downgrade my reaniamted to 2.6.0 then its work, but I want the latest version

@dohooo
Copy link
Owner

dohooo commented Jun 5, 2022

You don't need to add this code, just upgrade the carousel version to 2.6.0

I updated it, but not working, anyone else has this problem ? I have to downgrade my reaniamted to 2.6.0 then its work, but I want the latest version

Could try in this example? It used the latest version of reanimated.

@miamiappmachine
Copy link

Seems to cause some big issues with webpack. I get the following error using it with RNW and Next.js 12.1:

webpack_require.g.__reanimatedWorkletInit is not a function

TypeError: webpack_require.g.__reanimatedWorkletInit is not a function
at eval (webpack-internal:///./node_modules/react-native-reanimated-carousel/lib/commonjs/utils/dealWithAnimation.js:61:25)
at eval (webpack-internal:///./node_modules/react-native-reanimated-carousel/lib/commonjs/utils/dealWithAnimation.js:64:2)
at ./node_modules/react-native-reanimated-carousel/lib/commonjs/utils/dealWithAnimation.js (http://localhost:3000/_next/static/chunks/modules_slider_carousel_js.js:1548:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:678:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:37:33)
at fn (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:333:21)
at eval (webpack-internal:///./node_modules/react-native-reanimated-carousel/lib/commonjs/hooks/useCarouselController.js:12:26)
at ./node_modules/react-native-reanimated-carousel/lib/commonjs/hooks/useCarouselController.js (http://localhost:3000/_next/static/chunks/modules_slider_carousel_js.js:1378:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:678:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:37:33)
at fn (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:333:21)
at eval (webpack-internal:///./node_modules/react-native-reanimated-carousel/lib/commonjs/Carousel.js:14:30)
at ./node_modules/react-native-reanimated-carousel/lib/commonjs/Carousel.js (http://localhost:3000/_next/static/chunks/modules_slider_carousel_js.js:1328:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:678:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:37:33)
at fn (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:333:21)
at eval (webpack-internal:///./node_modules/react-native-reanimated-carousel/lib/commonjs/index.js:10:40)
at ./node_modules/react-native-reanimated-carousel/lib/commonjs/index.js (http://localhost:3000/_next/static/chunks/modules_slider_carousel_js.js:1468:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:678:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:37:33)
at fn (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:333:21)
at eval (webpack-internal:///./modules/slider/carousel.js:7:90)
at ./modules/slider/carousel.js (http://localhost:3000/_next/static/chunks/modules_slider_carousel_js.js:2954:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:678:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:37:33)
at Function.fn (http://localhost:3000/_next/static/chunks/webpack.js?ts=1654523863123:333:21)

FYI - 2.4.0 with calls to reanimatedWorklet removed via patch-package works fine.

@michel-adrion
Copy link

Hi, everyone.
I have resolved this issue by updating "react-native-reanimated": "~2.8.0" in package.json and deploying new release version of react-native-reanimated.

@dohooo
Copy link
Owner

dohooo commented Jun 10, 2022

fixed

@Wilted98
Copy link

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,
};

Thank you !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed needs review The issue has been solved, Wait for confirmation.
Projects
None yet
Development

No branches or pull requests