App.js에서 모듈을 확인할 수 없음-React Native

Nov 26 2020

나는 조용히 반응하는 새롭고 이것이 어리석은 일이라는 것을 알고 있지만 실제로는 볼 수 없습니다.

다음과 같은 오류가 발생합니다. "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>
    
    
    );
}

답변

MuralishankarSundaram Nov 26 2020 at 11:10

app.js 파일에서 폴더 순서를 확인하세요.

NoamanKhalil Nov 27 2020 at 22:15

이유는 모르겠지만 반응 이이 스크립트를 구현하는 방법에 문제가 있었으며 아래 방법으로 변경했으며 제대로 작동하는 것 같습니다.

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;