You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native报错Element type is invalid,求问题排查帮助

问题分析与解决方案

错误原因

你遇到的Uncaught Error: Invariant Violation: Element type is invalid错误,核心问题是HomeScreen中错误地从react包导入了Text和View组件。这两个组件属于react-native库,而非react库,当前导入的是整个react对象,并非可渲染的组件函数/类,导致React无法识别并渲染它们。

修复步骤

修改HomeScreen的导入语句,从react-native正确导入Text和View:

import React from "react";
// 替换错误的导入,从react-native导入组件
import { Text, View } from "react-native";

const HomeScreen = () => {
    return (
        <View>
            <Text>Det er min home</Text>
        </View>
    )
};

export default HomeScreen

验证说明

修改后,Text和View会被正确识别为React Native的内置组件,此时导航到HomeScreen就能正常渲染内容,不会再抛出组件类型无效的错误。

内容的提问来源于stack exchange,提问作者Willnewbie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 18:07:13