【问题标题】:EXPO React Native - Failed to initialize react-native-reanimated libraryEXPO React Native - 无法初始化 react-native-reanimated 库
【发布时间】:2022-11-30 02:35:46
【问题描述】:

使用抽屉导航时出现这些错误。

这是完整的 App.js

import { useEffect, useState } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';


import HomePage from './components/Pages/Home.Component';
import SearchPage from './components/Pages/Search.page';
import CardsPage from './components/Pages/Cards';

const Drawer = createDrawerNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="Home">
        <Drawer.Screen name="Home" component={HomePage} />
        <Drawer.Screen name="Search" component={SearchPage} />
        <Drawer.Screen name="Cards" component={CardsPage} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor:'#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  navbar:{
    marginBottom:'10%'
  }
});

babel.config.js

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      'react-native-reanimated/plugin'
  ]
  };
};

包.json

{
  "name": "talsmandb",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@expo/webpack-config": "^0.17.2",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/bottom-tabs": "^6.4.3",
    "@react-navigation/drawer": "^6.5.3",
    "@react-navigation/native": "^6.0.16",
    "@react-navigation/native-stack": "^6.9.4",
    "expo": "~47.0.8",
    "expo-status-bar": "~1.4.2",
    "react": "18.1.0",
    "react-dom": "18.1.0",
    "react-native": "0.70.5",
    "react-native-gesture-handler": "^2.8.0",
    "react-native-reanimated": "^2.12.0",
    "react-native-safe-area-context": "^4.4.1",
    "react-native-screens": "~3.18.0",
    "react-native-web": "~0.18.9",
    "react-navigation": "^4.4.4"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

如果我们删除 DrawerNavigation 导入并将代码更改为选项卡,则一切正常。

添加插件后我们已经清除了缓存。 我们已经完全卸载并重新安装了所有模块。

我们犯了什么愚蠢的错误?

【问题讨论】:

    标签: react-native expo navigation-drawer react-native-reanimated


    【解决方案1】:

    这对我有用。

    1. npm i react-native-reanimated
    2. 添加plugins:['react-native-reanimated/plugin'],在“<your_app_root_folder>/babel.config.js”中的预设下方。
    3. import 'react-native-gesture-handler'; 添加到“<your_app_root_folder>/App.js”的顶部。
    4. 使用npx react-native start --reset-cache 重置缓存。

    【讨论】:

      猜你喜欢
      • 2023-02-01
      • 2022-11-17
      • 1970-01-01
      • 2020-11-22
      • 2018-11-21
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 2022-10-19
      相关资源
      最近更新 更多