简体   繁体   English

无法从 App.js 解析模块 - React Native

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

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"我收到以下错误:无法从“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;

The above is my AppText script以上是我的 AppText 脚本

this is the app.js这是 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>
    
    
    );
}

Please check the folder order from the app.js file/请检查 app.js 文件中的文件夹顺序/

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.不知道为什么,但是 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;

Better check the files of screens must be inside in the core project folder .. I made a mistake now I sort it out最好检查屏幕文件必须在核心项目文件夹中..我犯了一个错误现在我把它整理出来

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native 程序从“App.js”返回“无法解析”srcscreensComponentsScreenListScreen“ - React Native program returns “Unable to resolve ”srcscreensComponentsScreenListScreen“ from ”App.js" 无法从…/App.js 解析模块“react-navigation”:Haste 模块 map 中不存在模块“react-navigation” - Unable to resolve module 'react-navigation' from …/App.js: Module 'react-navigation' does not exist in the Haste module map 无法从“App.js”解析“react-navigation-drawer” - Unable to resolve “react-navigation-drawer” from “App.js” 无法从“App.js”解析“@react-navigation/stack” - Unable to resolve “@react-navigation/stack” from “App.js” 无法从“App.js”解析“react-navigation-stack” - Unable to resolve “react-navigation-stack” from “App.js” React Native:“构建 JavaScript 包失败。 无法从“App.js”解析“@react-navigation/stack” - React native: “Failed building JavaScript bundle. Unable to resolve ”@react-navigation/stack“ from ”App.js“” 错误:无法从C:\\ Users \\ wanuuu27 \\ AwesomeProject \\ App.js中解析模块`react-redux`:模块`react-redux`不存在 - Error: Unable to resolve module `react-redux` from `C:\Users\wanuuu27\AwesomeProject\App.js`: Module `react-redux` does not exist 错误:无法从 G:\Workspace\FormApp\App.js 解析 module./navigators/MainNavigator: - Error: Unable to resolve module ./navigators/MainNavigator from G:\Workspace\FormApp\App.js: 无法解析模块。/SignIn In React Native 应用程序 - Unable to resolve module ./SignIn In React Native app 无法从“App.js”解析“aws-amplify” - Unable to resolve "aws-amplify" from "App.js"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM