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 workletInit is not a function #395

Closed
LoganxDev opened this issue Nov 20, 2020 · 23 comments
Closed

reanimated workletInit is not a function #395

LoganxDev opened this issue Nov 20, 2020 · 23 comments

Comments

@LoganxDev
Copy link

LoganxDev commented Nov 20, 2020

Trying to follow along with the gestures tutorial to create a draggable view and I get the following error when trying to use the usePanGestureHandler hook.

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

I see there's an issue in reanimated related to this, do I need to downgrade?

Package versions are:

"react-native-reanimated": "^2.0.0-alpha.9.1",
"react-native-redash": "^15.11.1"
@wcandillon
Copy link
Owner

@LoganxDev sorry that you experienced this. The issue and workaround is described here software-mansion/react-native-reanimated#1423

@LoganxDev
Copy link
Author

Ah okay that got me past the error, thanks!

@lcorniglione
Copy link

Hi,

I am having the exact same issue, but I cannot make that workaround work. Where I am supposed to put this function?

global.__reanimatedWorkletInit = () => {};

Thanks!

@wcandillon
Copy link
Owner

@lcorniglione Another workaround is to use reanimated. this will import the real init function.

@0xNoSignal
Copy link

0xNoSignal commented Dec 29, 2020

@wcandillon
What do you mean with "use reanimated"? I do use reanimated 2 in my project but that does not seem to help and the workaround does not seem to work either, I wrote global.__reanimatedWorkletInit = () => {}; on every possible file but still I keep on getting:

Error: Requiring module "node_modules/react-native-redash/lib/module/Animations.js", which threw an exception: TypeError: global.__reanimatedWorkletInit is not a function. (In 'global.__reanimatedWorkletInit(_f)', 'global.__reanimatedWorkletInit' is undefined)

I wonder where the problem is. Is it reanimated-2 which is making problems, expo 2 or redash. I can't seem to find it and I spend hours on it. Any ideas?

I am also happy for another workaround

"expo": "^40.0.0",
"react-native-reanimated": "2.0.0-rc.0",
"react-native-redash": "^16.0.4",

@wcandillon
Copy link
Owner

I might sound silly but this happens if you don't import the "react-native-reanimated" module. Because the reanimated plugin works but doesn't have access to the reanimated runtime.

@ghmeec
Copy link

ghmeec commented Feb 6, 2021

am getting the same error

@KestasVenslauskas
Copy link

Any update on this? How to actually fix this issue?

@thisisgit
Copy link

Thanks to this post, simply adding import 'react-native-reanimated'; on top of the file solved my issue.

@ehsan6sha
Copy link

For me putting import for react-native-reanimated before import for redash solved the issue

@Aaronhuu
Copy link

@nandorojo
Copy link

This issue is happening on Web in v2.8.0.

@UchennaOkafor
Copy link

This issue is happening on Web in v2.8.0.

Did you manage to solve it?

@nandorojo
Copy link

Yeah. Upgrade to the latest RNGH (2.4.1), the latest Reanimated, make sure you don’t have duplicate versions with yarn why, remove .next or any corresponding cache folders, and run yarn

@himrocks33
Copy link

@nandorojo I'm still having the same issue on web even after your suggested fix. Any ideas?

@exzos28
Copy link

exzos28 commented May 14, 2022

Start metro with cache reset
yarn start --reset-cache

This helped me solve the problem

@Gamma169
Copy link

Gamma169 commented Jun 4, 2022

@nandorojo and for those of you running into the problem v2.8.0 on web, I was able to resolve the issue by adding global.__reanimatedWorkletInit = () => {}; to /lib/reanimated2/core.js Note that it is the lib folder and not the src folder that made it work.

@wrsulliv
Copy link

wrsulliv commented Jul 8, 2022

Thanks @Gamma169 this worked for me. Did you find a longer-term solution since posting this workaround?

@Gamma169
Copy link

Gamma169 commented Jul 9, 2022

@wrsulliv, are you familiar with patch-package? I created a patch file to automatically add the line when I run yarn. So I don't have to worry about it, and haven't thought of it since.

@wcandillon
Copy link
Owner

@Gamma169 can I see the patch? anything we could add to redash?

@wrsulliv
Copy link

Thanks @Gamma169 I ended up doing the same. I documented is here if it helps @wcandillon : software-mansion/react-native-reanimated#3111 (comment)

@wcandillon
Copy link
Owner

@wrsulliv Thank you for following up on this. With Reanimated on web, I am not experiencing the issue. Let me know if there are any changes you would like me to add to this package. By looking at the issue you linked on github it wasn't obvious what I should do.

@challme28
Copy link

challme28 commented Nov 9, 2022

@nandorojo and for those of you running into the problem v2.8.0 on web, I was able to resolve the issue by adding global.__reanimatedWorkletInit = () => {}; to /lib/reanimated2/core.js Note that it is the lib folder and not the src folder that made it work.

It worked for me.
I think is the cleanest solution, no polyfill file or git project modified.

Edit: npx react-native-clean-project made it work as well. It didn't the first few times, but after a while it did, for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests