NodeJS 为什么我在React Native应用程序中遇到“Element type is invalid”错误?

rsl1atfo  于 2023-05-28  发布在  Node.js
关注(0)|答案(1)|浏览(156)
`import { StyleSheet, Text } from 'react-native';
import { Provider } from 'react-redux';
import { store } from './store';
import { HomeScreen } from './screens/HomeScreen';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { SafeAreaView } from 'react-native-safe-area-view';

// Redux installed

export default function App() {
  return (
    <Provider store={store}>
      <SafeAreaProvider>
        <HomeScreen />
      </SafeAreaProvider>
    </Provider>
  );
};

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

ERROR错误:元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。
检查App的渲染方法。
有人能帮我吗?
以下是其他文件:HomeScreen.js:

`import { StyleSheet, Text, View, SafeAreaView, Image } from 'react-native';
import React from 'react';
import tw from "tailwind-react-native-classnames";
import NavOptions from '../components/NavOptions';

/// Tailwind CSS 
const HomeScreen = () => {
  return (
    <SafeAreaView style={tw`bg-white h-full`}>
      <View style = {tw`p-5`}>
        <Image
        style ={{ 
            width:100, 
            height:100, 
            resizeMode: 'contain',
        }}
            source = {{
                uri:"https://links.papareact.com/gzs",
            }}
        />
        <NavOptions />

      </View>
    </SafeAreaView>
  );
};

export default HomeScreen;

const styles = StyleSheet.create({
    text: {
        color:"blue",
    },
});`

store.js

`import { configureStore } from "@reduxjs/toolkit";
import { navReducer } from "./slices/navSlice";

export const store = configureStore({
    reducer: {
        nav: navReducer,
    },
});`

我试过查看react元素来修复它,但它们都没有帮助。我觉得这可能与NPM有关。

l0oc07j2

l0oc07j21#

您将HomeScreen导出为默认模块,您需要在导入时不使用花括号。

import HomeScreen from './screens/HomeScreen';

相关问题