react-native-reanimated: Error: Requiring module "node_modules\react-native-reanimated\src\Animated.js", which threw an exception: Error: Reanimated 2 failed to create a worklet, maybe you forgot to add Reanimated's babel plugin?
Description
I am trying to use createDrawerNavigator from import { createDrawerNavigator } from ‘@react-navigation/drawer’; in react native. However, I am getting the error above
Expected behavior
The expected behavior is to work as described in the documentation however on the ground it is different.
Actual behavior & steps to reproduce
Add import ‘react-native-gesture-handler’; at the top of my App.js In babel.config.js add reanimated/plugin as below
module.exports = function(api) {
api.cache(true);
return {
presets: [
'babel-preset-expo',
'module:metro-react-native-babel-preset'
],
plugins: [
'react-native-reanimated/plugin',
]
};
};
Snack or minimal code example
Below is my Drawer.js file
import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
onPress={() => navigation.navigate('Notifications')}
title="Go to notifications"
/>
</View>
);
}
function NotificationsScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button onPress={() => navigation.goBack()} title="Go back home" />
</View>
);
}
const Drawer = createDrawerNavigator();
export default function MyDrawer() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}
Package versions
- React Native:
- React Native Reanimated:
Affected platforms
- Android
- iOS
- Web
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 29 (2 by maintainers)
I had the same issue. Found this on Expo.
https://docs.expo.dev/versions/latest/sdk/reanimated/#installation
add the plugins line to your babel.config.js
module.exports = function (api) { api.cache(true) return { presets: [‘babel-preset-expo’], plugins: [‘react-native-reanimated/plugin’],
} }
Run expo r -c After adding below code to babel.config.js
module.exports = function (api) { api.cache(true) return { presets: [‘babel-preset-expo’], plugins: [‘react-native-reanimated/plugin’], } }
@lewisMachilika Try to reset metro bundler cache.
yarn start --reset-cache
.If you can check
I have already added that code but its still not working
Still an issue using SDK 45
it worked through expo r -c
Having the same issue here, using SDK 45 and can’t fix it 😦
I created a brand new expo project…none of these solutions worked for me 😣
After edited the babel.config.js file, try with:
expo start --clear
It works for meDid you try to clear cache according to @ammarahm-ed 's suggestions?
yarn start --reset-cache
It looks like a cache issue.I had this problem using SDK 44 and tried following steps I found online, nothing works. But then I solved it with this steps:
I just followed the documentation here https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/
after following that I run expo doctor --fix-dependencies to fix the compatibility issue.
I didn’t run expo r -c, but you might also need to run it.
I found a solution, which fixed the issue in my case. Stackoverflow: https://stackoverflow.com/questions/61067004/invariant-violation-calling-synchronous-methods-on-native-modules-is-not-suppor
This is temporary fix. This is working perfectly on my side. you have to edit this file
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js
problem is in react reanimated dependency which is used by drawer navigator and expo stored tat file so we have to reset expo cache and add plugin to babel.config which by default not installed while intalling dependencies
why this major issue is closed ? this issue still exist, wasting time on this bug from last one week