React Native 应用程序无法解析组件。
我正在尝试Test.jsx
在App.js
.
我收到以下错误-
error: bundling failed: Error: Unable to resolve module `./screens/Test` from App.js`:
The module `./screens/Test` could not be found from App.js. Indeed, none of these files exist
项目经理(或者更确切地说是文件)看起来像这样-
Test.js 代码-
import React, { Component } from 'react';
import {View, Text, StyleSheet} from 'react-native'
export default class Test extends Component {
render() {
return (
<View style={styles.container}>
<Text>Hello World?</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});
App.js 代码-
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import Test from "./screens/Test";
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<Test />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
我确实尝试了提到的所有解决方案 - react-native#4968,但似乎没有一个有效。我也提到了this,但是,解决方案是针对 css 的,与解决此问题的方法相去甚远。
我已经查看了更多问题,并且不知道我还需要做什么。我还创建了一个新项目(截图和代码来自新项目)。
我错过了什么?
更新:
我意识到这个问题是因为我有.jsx
扩展。导入.js
文件工作正常。有关如何使项目接受.jsx
导入的任何指示?