Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Failed to initialize react-native-reanimated library

I was working on a project on react native trying to create drawer navigation

  • I installed a navigation drawer, gesture handler, and reanimated libraries

  • and when I run I got an error 1st error :

    ERROR Error: Failed to initialize react-native-reanimated library, make sure you followed installation steps here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/

    1. Make sure reanimated's babel plugin is installed in your babel.config.js (you should have 'react-native-reanimated/plugin' listed there - also see the above link for details)
    2. Make sure you reset build cache after updating the config, run: yarn start --reset-cache, js engine: hermes

so I did according to the suggestion in this error I added plugins:['react-native-reanimated/plugin' in the babel.config.js and started with npm start ----reset cache that gave me another error:

2nd error

error: index.js: Unknown option: .Plugins. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options.

here is my package.json

{
  "name": "Train",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/drawer": "^6.5.0",
    "@react-navigation/native": "^6.0.13",
    "@react-navigation/stack": "^6.3.1",
    "react": "18.1.0",
    "react-native": "0.70.1",
    "react-native-gesture-handler": "^2.6.2",
    "react-native-reanimated": "^2.10.0",
    "react-native-safe-area-context": "^4.3.4",
    "react-native-screens": "^3.17.0",
    "react-navigation-stack": "^2.10.4"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.72.1",
    "react-test-renderer": "18.1.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

my index.js

import {AppRegistry} from 'react-native';
import App from './App';
import Login from './pages/Login';
import Home from './pages/Home';
import cart from './pages/Drawer/cart';
import items from './pages/Drawer/items';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

my babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  Plugins:['react-native-reanimated/plugin'],//I added this line because of the 1st error 
};

my app.js

import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator} from '@react-navigation/stack';
import {createDrawerNavigator} from '@react-navigation/drawer';

//for stack
import Login from './pages/Login';
import Home from './pages/Home';
//for drawer
import cart from './pages/Drawer/cart';
import items from './pages/Drawer/items';
import wallet from './pages/Drawer/wallet';
import orders from './pages/Drawer/orders';


const stack = createStackNavigator();
const Drawer = createDrawerNavigator();

function MystackNav(){
  return(
    <stack.Navigator>
      <stack.Screen name='Login' component={Login} options={{headerShown:false}}/>
      <stack.Screen name='Home' component={Home} options={{headerShown:false}}/>
      <stack.Screen name='Drawer' component={MyDrawer}/>
    </stack.Navigator>
  )
}

function MyDrawer(){
  return(
    <Drawer.Navigator>
      <Drawer.Screen name='cart' component={cart}/>
    </Drawer.Navigator>
  )
}

export default function App(){
  return(
    <NavigationContainer>
      <MystackNav/>
    </NavigationContainer>
  )
}
like image 342
Abhiram Avatar asked Apr 14 '26 10:04

Abhiram


1 Answers

1.Update babel.config.js

  module.exports = {
    presets: [
      ...
    ],
    plugins: [
      ...
      'react-native-reanimated/plugin',
    ],
  };

2.run expo start -c

references - https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/

like image 180
Sandee007 Avatar answered Apr 16 '26 00:04

Sandee007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!