Javascript React Native:找不到我的(创建的)组件?
我和react native开始了一个新项目。我在app/components/Home/中创建了一个名为Home.jsx的组件。看起来是这样的:Javascript React Native:找不到我的(创建的)组件?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我和react native开始了一个新项目。我在app/components/Home/中创建了一个名为Home.jsx的组件。看起来是这样的: import React, { Component } from 'react'; import { View, Text, StyleSheet, } from 'react-native'; export default class Home extends Component { render() { return
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
} from 'react-native';
export default class Home extends Component {
render() {
return (
<View style={styles.container}>
<Text>This is the home component!</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default Home;
import {AppRegistry} from 'react-native';
import Home from './app/components/home/Home';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => Home);
当我尝试在emulator中加载应用程序时,会收到以下错误消息:
error: bundling failed: Error: Unable to resolve module
`./app/components/home/Home` from
`/Users/[my_name]/repos/[repo_name]/index.js`:
The module `./app/components/home/Home` could not be found from
`/Users/[my_name]/repos/[repo_name]/index.js`. Indeed, none of these
files exist:
我做错了什么?我没有使用名为app的文件夹,而是使用了src。我不完全确定这为什么解决了这个问题,但我们走吧 这可能是因为要将Home类导出为默认类两次,请尝试删除导出默认Home;在底部。嘿,试过了,不幸的是,还是同一条错误消息!