1

I am quiet new to react and I know this is something stupid but I really cant see it.

I get the following error : Unable to resolve "./app/components/Apptext" from "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;

The above is my AppText script

this is the 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>
    
    
    );
}
3
  • Is the AppText.js file inside a components folder which is inside an app folder? Commented Nov 25, 2020 at 19:01
  • @ShamarYarde Yes ! Commented Nov 26, 2020 at 9:55
  • Did you try reloading the application, or cleaning the cache: stackoverflow.com/a/41049449/8121551 or medium.com/@abhisheknalwaya/…? The simulator might be using a previous build which was looking for the wrong directory. Commented Nov 27, 2020 at 13:55

3 Answers 3

0

Please check the folder order from the app.js file/

Sign up to request clarification or add additional context in comments.

1 Comment

app.js is in the root folder and the Apptext script being sub folder called /app/components/Apptext
0

No idea why but react had a issue with how i implmented this script, I changed it to the way below and it seems to be working fine.

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;

Comments

0

Better check the files of screens must be inside in the core project folder.. I made a mistake now I sort it out

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.