簡體   English   中英

無法從 App.js 解析模塊 - React Native

[英]Unable to resolve module from App.js - React Native

我很安靜,沒有反應,我知道這很愚蠢,但我真的看不到。

我收到以下錯誤:無法從“App.js”解析“./app/components/Apptext”

import React, { Component } from 'react';
import { Text,StyleSheet,Platform } from 'react-native';

function AppText ({children})
{
return <Text style = {styles.text}>{children}</Text>
}



const styles = StyleSheet.create({

text:{
    color:"tomato",
   

    ...Platform.select({
        ios:{
            fontSize:20,
            fontFamily:"Avenir"
        },
        android:{
            fontSize:18,
            fontFamily:"Roboto"
        }
    })
},

})
export default AppText;

以上是我的 AppText 腳本

這是 app.js

import { StatusBar } from 'expo-status-bar';
import React, { Fragment } from 'react';
import {Dimensions ,SafeAreaView, StyleSheet,TouchableWithoutFeedback,Alert, Text, View ,Image, Button,Platform, BackHandler} from 'react-native';
import{ useDimensions,useDeviceOrientation } from '@react-native-community/hooks';
import WelcomeScreen from './app/screens/WelcomeScreen';
import AppText from './app/components/Apptext';


export default function App() {
  return (
<View style ={{flex:1,justifyContent:"center",alignItems:"center",}}>
      <AppText>I like react</AppText>
    </View>
    
    
    );
}

請檢查 app.js 文件中的文件夾順序/

不知道為什么,但是 react 對我如何實現這個腳本有問題,我把它改成下面的方式,它似乎工作正常。

import React from "react";
import { Text, StyleSheet, Platform } from "react-native";

function AppText({ children, style }) {
  return <Text style={[styles.text, style]}>{children}</Text>;
}

const styles = StyleSheet.create({
  text: {
    fontSize: 18,
    fontFamily: Platform.OS === "android" ? "Roboto" : "Avenir",
  },
});

export default AppText;

最好檢查屏幕文件必須在核心項目文件夾中..我犯了一個錯誤現在我把它整理出來

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2025 STACKOOM.COM