question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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?

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:28 (2 by maintainers)

github_iconTop GitHub Comments

28reactions
lewisMachilikacommented, Dec 31, 2021

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’], } }

27reactions
patrickdunagancommented, Dec 29, 2021

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’],
} }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reanimated 2 failed to create a worklet, maybe you forgot ...
The error is: Reanimated 2 failed to create a worklet, maybe you forgot to add Reanimated's babel plugin? react-native ...
Read more >
Error: Reanimated 2 failed to create a worklet
Pop over to babel.config.js, simply add 'react-native-reanimated/plugin' under ... Error: Reanimated 2 failed to create a worklet — Maybe You Forgot to Add...
Read more >
Reanimated 2 failed to create a worklet, maybe you forgot ...
When I add this imports I get title error. import Animated, { useAnimatedStyle, useSharedValue, withDelay, withRepeat, withTiming, ...
Read more >
Reanimated
Reanimated. react-native-reanimated provides an API that greatly simplifies the process of creating smooth, powerful, and maintainable animations.
Read more >
Installation | React Native Reanimated
After adding the react-native-reanimated/plugin to your project you may encounter a false-positive "Reanimated 2 failed to create a worklet" error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found