javascript - 无法从 C:\Users\vkgan\ForRealNow\navigators\RootStack.js 解析模块 ./screens/Login:
问题描述
react-navigation
自从我实施到我的expo
react-native
项目中以来,我一直收到此错误。这是完整的错误消息:
无法从 C:\Users\vkgan\ForRealNow\navigators\RootStack.js 解析模块 ./screens/Login:
这些文件都不存在:
- 导航器\screens\Login(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios .jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
- 导航器\屏幕\登录\索引(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js| .ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
RootStack.js:
// import react navigation
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
// import screens
import Login from './screens/Login';
import Signup from './screens/Signup';
import Welcome from './screens/Welcome';
// Colors
import {Colors} from './components/styles';
const{brand, darkLight, primary, tertiary } = Colors;
import React from 'react';
const Stack = createStackNavigator();
const ArrowStack = () => {
return(
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerStyled: {
backgroundColor: 'transparent'
},
headerTintColor: tertiary,
headerTransparent: true,
headerTitle: '',
headerLeftContainerStyle:{
paddingLeft:20
}
}}
initialRouteName="Login"
>
<Stack.screen name="Login" component={Login} />
<Stack.screen name="Signup" component={Signup} />
<Stack.screen options={{ headerTintColor: primary }} name="Welcome" component={Welcome} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default ArrowStack;
包.json:
{
"name": "forrealnow",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-native-community/datetimepicker": "3.5.2",
"@react-navigation/native": "^6.0.6",
"@react-navigation/stack": "^6.0.11",
"expo": "~43.0.0",
"expo-constants": "~12.1.3",
"expo-status-bar": "~1.1.0",
"formik": "^2.2.9",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.2",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.8.0",
"react-native-web": "0.17.1",
"styled-components": "^5.3.3"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
登录.js:
import React, {useState} from 'react';
import { StatusBar } from 'expo-status-bar';
//formik
import {Formik} from 'formik';
//icons
import {Octicons, Ionicons, Fontisto } from '@expo/vector-icons';
import{
StyledContainer,
InnerContainer,
PageLogo,
PageTitle,
SubTitle,
StyledFormArea,
LeftIcon,
StyledInputLabel,
StyledTextInput,
RightIcon,
Colors,
StyledButton,
ButtonText,
MsgBox,
Line,
ExtraView,
ExtraText,
TextLink,
TextLinkContent
} from './../components/styles'
import {Keyboard, View} from 'react-native';
// Colors
const{brand, darkLight, primary} = Colors;
// keyboard avoiding view
import KeyboardAvoidingwrapper from '../components/KeyboardAvoidingwrapper';
const Login = ({navigation}) => {
const {hidePassword, setHidePassword} = useState(true);
return(
<KeyboardAvoidingwrapper>
<StyledContainer>
<StatusBar style="dark"/>
<InnerContainer>
<PageLogo resizeMode= 'cover'source={require('./../assets/icon.png')}/>
<PageTitle>Flower Crib</PageTitle>
<SubTitle>Account Login</SubTitle>
<Formik
initialValues={{email: '', password: ''}}
onSubmit={(values) => {
console.log(values)
navigation.navigate("Welcome");
}}
>{({handleChange, handleBlur, handleSubmit, values}) => (<StyledFormArea>
<MyTextInput
label="Email Address"
icon="mail"
placeholder="johndoe@gmail.com"
placeholderTextColor={darkLight}
onChangeText={handleChange('email')}
onBlur={handleBlur('email')}
value={values.email}
keyboardType="email-address"
/>
<MyTextInput
label="Password"
icon="lock"
placeholder="*************"
placeholderTextColor={darkLight}
onChangeText={handleChange('password')}
onBlur={handleBlur('password')}
value={values.password}
secureTextEntry={hidePassword}
isPassword={true}
hidePassword={hidePassword}
setHidePassword={setHidePassword}
/>
<MsgBox>...</MsgBox>
<StyledButton onPress={handleSubmit}>
<ButtonText>
Login
</ButtonText>
</StyledButton>
<Line />
<StyledButton google={true} onPress={handleSubmit}>
<Fontisto name="google" color={primary} size={25} />
<ButtonText google={true}>
Sign in with Google
</ButtonText>
</StyledButton>
<ExtraView>
<ExtraText>
Don't have an account already?
</ExtraText>
<TextLink onPress={() => navigation.navigate("Signup")}>
<TextLinkContent>Signup</TextLinkContent>
</TextLink>
</ExtraView>
</StyledFormArea>)}
</Formik>
</InnerContainer>
</StyledContainer>
</KeyboardAvoidingwrapper>
);
}
const MyTextInput = ({label, icon, isPassword, hidePassword, setHidePassword, ...props}) =>{
return(
<View>
<LeftIcon>
<Octicons name={icon} size={30} color={brand} />
</LeftIcon>
<StyledInputLabel>{label}</StyledInputLabel>
<StyledTextInput {...props}/>
{isPassword && (
<RightIcon onPress={() => setHidePassword(!hidePassword)}>
<Ionicons name={hidePassword ? 'md-eye-off' : 'md-eye'} size={30} color={darkLight}/>
</RightIcon>
)}
</View>
)
}
export default Login;
应用程序.js
import React from 'react';
//import Root Stack
import RootStack from './navigators/RootStack';
export default function App() {
return (
<RootStack/>
);
}
请让我知道我是否应该提供任何其他信息
解决方案
Login
存在于文件screens
夹和文件夹中。RootStack
navigators
所以在RootStack.js
导入screens
文件夹的文件中是这样的:
import Login from '../screens/Login';
import Signup from '../screens/Signup';
import Welcome from '../screens/Welcome';
推荐阅读
- javascript - 单击锚点时如何停止悬停?
- javascript - 如果输入有值,如何将输入标签放在顶部
- ios - IOS - 当滑块值改变时设置 UILabel Swift
- haskell - 特定函数名称“it”会发生什么?
- asp.net-core - 如何在 .NET Core - Web API 中根据文化显示正确的资源语言?
- c# - C# Linq - 根据用户输入创建动态选择查询
- git - Git忽略文件仍列在未跟踪列表中
- html - 如何创建一个跨越大屏幕两列和移动设备一列的列表?
- django - Ajax 没有向 django 视图发送数据
- python - 如何使用 Python 在多个 Excel 工作表中附加不同的表格?