Nie można rozpoznać modułu z App.js - React Native
Nov 26 2020
Jestem cicho nowy, aby zareagować i wiem, że to coś głupiego, ale naprawdę nie mogę tego zobaczyć.
Pojawia się następujący błąd: Nie można rozpoznać pliku „./app/components/Apptext” z „App.js”
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;
Powyższe to mój skrypt AppText
to jest plik 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>
);
}
Odpowiedzi
MuralishankarSundaram Nov 26 2020 at 11:10
Sprawdź kolejność folderów w pliku app.js /
NoamanKhalil Nov 27 2020 at 22:15
Nie mam pojęcia, dlaczego, ale zareagowałem, miałem problem ze sposobem implementacji tego skryptu, zmieniłem go na sposób przedstawiony poniżej i wydaje się, że działa dobrze.
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;