Android React native:无法解析模块事实上,这些文件均不存在:
下面我将在我的react原生项目中使用Android React native:无法解析模块事实上,这些文件均不存在:,android,reactjs,react-native,components,custom-component,Android,Reactjs,React Native,Components,Custom Component,下面我将在我的react原生项目中使用FloatingTitleTextInputField 下面是我的项目结构 这是我的HomeScreen.js import React, {Component} from 'react'; import {Text, View, TextInput, StyleSheet} from 'react-native'; import FloatingTitleTextInputField from './customComponents/floating_t
FloatingTitleTextInputField
下面是我的项目结构
这是我的HomeScreen.js
import React, {Component} from 'react';
import {Text, View, TextInput, StyleSheet} from 'react-native';
import FloatingTitleTextInputField from './customComponents/floating_title_text_input_field';
export default class HomeScreen extends Component {
render() {
return (
// <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
// <Text>My First React App</Text>
// <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}} />
// </View>
<View style={styles.container}>
<View style={styles.container}>
<Text style={styles.headerText}>Its Amazing</Text>
<FloatingTitleTextInputField
attrName="firstName"
title="First Name"
value={this.state.firstName}
updateMasterState={this._updateMasterState}
/>
<FloatingTitleTextInputField
attrName="lastName"
title="Last Name"
value={this.state.lastName}
updateMasterState={this._updateMasterState}
/>
</View>
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 65,
backgroundColor: 'white',
},
labelInput: {
color: '#673AB7',
},
formInput: {
borderBottomWidth: 1.5,
marginLeft: 20,
borderColor: '#333',
},
input: {
borderWidth: 0,
},
});
有人能帮我解决这个问题吗
如果需要更多信息,请务必让我知道。提前谢谢。感谢您的努力。您正在从
主屏幕
组件中引用它,该组件位于屏幕
目录中。因为您使用的是local./path,所以它试图在屏幕/customComponents
中找到它。使用。/customComponents/floating\u title\u text\u input\u field
应该可以解决这个问题。即使在require
语句中使用了错误的路径,我想分享一下我是如何解决这个问题的可能会很有用,因为文件导入路径不是错误的原因。在我添加了一些图像资产并在组件中需要它们之后,我遇到了这个问题。但我忘了再次构建应用程序。经过几次尝试,这是对我有效的解决方案
warn Start
启动开发服务器尝试从“../customComponents/floating_title_text_输入字段”导入FloatingTitleTextInputField@bk7感谢您的快速回复让我检查一下谢谢我尝试从“../customComponents/FloatingTitleTextInputField”使用导入FloatingTitleTextInputField代码>但是仍然得到相同的错误对不起,我把文件写错了,是骆驼案。我已经改正了above@GokuFWIW,而不是使用相对路径,我通常引用项目根目录中的项目,如
myprojectname/customComponents/floating\u title\u text\u input\u field
。祝你好运
error Unable to resolve module `./floating_title_text_input_field` from `React Native/AwesomeProject/screens/
HomeScreen.js`: The module `./floating_title_text_input_field` could not be found from `/React Native/AwesomeProject/screens/HomeScreen.js`. Indeed, none of these files exist:
* `/React Native/AwesomeProject/screens/floating_title_text_input_field(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
* `/React Native/AwesomeProject/screens/floating_title_text_input_field/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`. Run CLI with --verbose flag for more details.
Error: Unable to resolve module `./floating_title_text_input_field` from `React Native/AwesomeProject/screens/HomeScreen.js`: The module `./floating_title_text_input_field` could not be found from `/React Native/AwesomeProject/screens/HomeScreen.js`. Indeed, none of these files exist: