javascript - 反应本机错误'无法解析模块......'
问题描述
'Unable to resolve module './app/screens/loginForm' from '/Users/salwabadreddine/Desktop/moappetit/app/screens/navigation.js'
即使我已将 loginForm 保存在该目录中,即使我尝试将代码复制并粘贴loginForm.js
到,我仍然会收到此
错误,但Navigation.js
会显示正确的输出并且不会发生错误。但是,当我尝试将其导入时,loginForm
它Navigation.js
会给我这个错误。任何帮助都会很棒。
//Navigation.js file
import { createStackNavigator } from 'react-navigation-stack';
import { Button } from 'react-native-material-ui';
import LoginScreen from './app/screens/loginForm';
import React from 'react';
import {View, StyleSheet} from 'react-native';
import{ createAppContainer } from 'react-navigation';
import { TextField } from 'react-native-materialui-textfield';
class InitialScreen extends React.Component {
render() {
return (
<View style={styles.container}>
<Button
style={{ container: styles.buttonStyle}}
primary={true}
text="Login"
raised={true}
onPress={() => this.props.navigation.navigate('Login')}/>
<Button
style={{ container: styles.buttonStyle}}
primary={true}
text="Register"
raised={true}
onPress={() => this.props.navigation.navigate('Register')}/>
</View>
);
}
}
class RegisterScreen extends React.Component {
render() {
return (
<View style={styles.container}>
<Button
style={{ container: styles.buttonStyle}}
primary={true}
text="Go back"
raised={true}
onPress={() => this.props.navigation.goBack()}/>
</View>
);
}
}
const AppNavigator = createStackNavigator({
Initial: InitialScreen,
Login: LoginScreen,
Register: RegisterScreen,
}, {
initialRouteName: 'Initial',
});
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
paddingTop: 50,
},
buttonStyle: {
width: 100,
height: 40,
backgroundColor: 'rgba(12, 57, 14, 0.85)',
},
submitButtonStyle: {
backgroundColor: 'rgba(12, 57, 14, 0.85)',
}
});
const Container = createAppContainer(AppNavigator);
export default Container;
//loginForm.js file:
import React from 'react';
import {View, StyleSheet} from 'react-native';
import {Button} from 'react-native-material-ui';
import { TextField } from 'react-native-materialui-textfield';
export default class LoginScreen extends React.Component {
// Initializing state
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
};
}
// Handling change when user enters text for email
handleEmailChange = email => {
this.setState({email})
}
// Handling change when user enters text for password
handlePasswordChange = password => {
this.setState({password})
}
loginAPI = async (email, password) => {
try {
var requestOptions = {
"method": "POST",
"headers": {
"Content-Type": "application/json"
}
};
var body = {
"provider": "email",
"data": {
"email": email,
"password": password
}
};
requestOptions.body = JSON.stringify(body)
const response = await fetch("https://auth.moappetit.com/v1/login", requestOptions)
const result = await response.json() // result.auth_token will return the auth token for current session
console.log(result)
} catch (e) { console.log(e) }
}
// Rendering to the UI the Input options and form button
render() {
return (
<View style={styles.container}>
<TextField tintColor='rgba(12, 57, 14, 0.85)'
required
value= {this.state.email}
onChangeText={this.handleEmailChange}
label="Email"
/>
<TextField tintColor='rgba(12, 57, 14, 0.85)'
required
secureTextEntry={true}
value= {this.state.password}
onChangeText={this.handlePasswordChange}
label="Password"
/>
<View>
<Button style={{ container: styles.buttonStyle}} text="Login" raised={true} primary={true} onPress={ () => this.loginAPI(this.state.email, this.state.password)}/>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: 50,
},
buttonStyle: {
backgroundColor: 'rgba(12, 57, 14, 0.85)',
},
});
解决方案
推荐阅读
- r - 使用 group_by 时添加总体平均值
- php - 如何设置 PHP 服务器?
- node.js - 如何在 Cypress 中使用与 Axios 相同的节点环境
- themes - Prestashop 儿童主题
- azure-logic-apps - microsoft flow null required parameter
- laravel-5 - 带有标签输入的 Laravel Bootstrap 4
- terraform - 结构 terraform 模板和文件夹的建议
- javascript - dragover 事件,目标需要是可拖动的元素
- html - 在 svg 中绘制路径,垂直线之间有 90° 弧
- cordova - 离子类型错误:无效数据