'不变违规:requireNativeComponent:在 UIManager 中找不到“RNSScreen”。' react本机cli中的错误

IT技术 reactjs macos react-native npm npm-install
2021-05-03 10:47:02

我不断收到 RNSScreen 错误。我已经按照 react-navigation guide 上的所有说明进行操作,但没有任何效果对我有用。

2个回答

看起来本机包不会自动链接。所以试试这个

注意:在您的情况下,它可以'../'代替,'../../../'因为我使用的是 Monorepo。

播客文件

pod 'RNScreens', :path => '../../../node_modules/react-native-screens/'
pod 'RNGestureHandler', :path => '../../../node_modules/react-native-gesture-handler/'
pod 'react-native-safe-area-context', :path => '../../../node_modules/react-native-safe-area-context/'

然后安装豆荚

yarn podinstall

然后终止已经运行的 MetroBundler 终端。并且,再次构建应用程序

yarn ios

工作示例

/**
 * @format
 */
import 'react-native-gesture-handler';
import {AppRegistry} from 'react-native';

import SplashScreen from '../common/src/containers/splashScreen';
import LoginScreen from '../common/src/containers/loginScreen';
import LoginOTPScreen from '../common/src/containers/loginOTPScreen';
import SearchScreen from './src/searchScreen';

import React from 'react';
import {name as appName, displayName} from './app.json';
import {Provider as PaperProvider} from 'react-native-paper';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';

import {enableScreens} from 'react-native-screens';
enableScreens();

const Stack = createStackNavigator();
const App = () => {
  return (
    <PaperProvider>
      <NavigationContainer>
        <Stack.Navigator initialRouteName="SplashScreen">
          <Stack.Screen name="SplashScreen" component={SplashScreen} />
          <Stack.Screen name="LoginScreen" component={LoginScreen} />
          <Stack.Screen name="LoginOTPScreen" component={LoginOTPScreen} />
          <Stack.Screen name="SearchScreen" component={SearchScreen} />
        </Stack.Navigator>
      </NavigationContainer>
    </PaperProvider>
  );
};

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

确保import 'react-native-gesture-handler';顶部

我遇到了这个错误并且正在做expo start --dev-client,当我刚做的时候expo start它就起作用了。