无法导入React Native中的其他组件

无法导入React Native中的其他组件

问题描述:

最近我开始学习如何使用React Native构建移动应用程序,我从我的一位朋友那里听说了它,而且我真的很感兴趣。但现在我面临错误,并试图从谷歌搜索解决方案,但他们都不能解决我的问题。我的问题是,当我输入其他组件index.android.js它显示的手机屏幕上的错误=>无法导入React Native中的其他组件

开发服务器返回的响应错误代码:500

我的组件存储在文件夹机器人 => 机器人/应用/组件/ Bar.js

我导入像这样

从'./app/components/Bar'导入Bar;

index.android.js

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    StyleSheet, 
    View 
} from 'react-native'; 

import Bar from './app/components/Bar'; 
export default class ProfilePageApp extends Component { 
    render() { 
    return (
     <View style={styles.container}> 

      <Bar /> 

     </View> 
    ); 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    backgroundColor: '#000', 
    } 
}); 

AppRegistry.registerComponent('ProfilePageApp',() => ProfilePageApp); 

Bar.js

import React, { Component } from 'react'; 
import { 
    View, 
    Text 
} from 'react-native'; 


class Bar extends Component { 
    render() { 
    return (
     <View style={styles.container}> 

      <Text>Hello world</Text> 

     </View> 
    ); 
    } 
} 

export default Bar; 

错误

enter image description here

+0

我认为这与es6导入和更多与反应服务器有关;尝试 ''' $守望手表德尔 - 所有 $室射频$ TMPDIR /反应,packager- * $ NPM安装 $ NPM启动 ''' –

我不确定RN在文件目录约定中的确如何工作,但我认为它与React等其他人几乎一样。但是,当我读取您的代码时,我认为您在import声明中缺少./android

你提到:

我的组件存储在文件夹中的Android => 的Android /应用/组件/ Bar.js

但你导入它像这样:

import Bar from './app/components/Bar'; 

您试过

import Bar from './android/app/components/Bar'; 

+0

感谢的人!!!!我完全没有注意到。 –