0

最近我開始學習如何使用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啓動 ''' –

回答

1

我不確定RN在文件目錄約定中的確如何工作,但我認爲它與React等其他人幾乎一樣。但是,當我讀取您的代碼時,我認爲您在import聲明中缺少./android

你提到:

我的組件存儲在文件夾中的Android => 的Android /應用/組件/ Bar.js

但你導入它像這樣:

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

您試過

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

+0

感謝的人!!!!我完全沒有注意到。 –

相關問題