React Native - 无法解析模块

时间:2017-09-29 14:07:57

标签: android react-native

在添加此问题之前,我已检查过以前的答案。不幸的是,我没有找到任何适合这个。我是React Native的初学者,我正在学习教程。我收到了这个错误。

enter image description here

index.android.js

import React from 'react';
import { AppRegistry } from 'react-native';
import Header from './src/components/header';

const App = () =>(
    <Header/>
);


AppRegistry.registerComponent('albums' , ()=>App);

header.js

    import React from 'react';
import { Text } from 'react-native';

const Header = () => {
  return <Text> Albums ! </Text>;
};

export default Header;

3 个答案:

答案 0 :(得分:0)

//import lib
import React from 'react';
import {AppRegistry,View} from 'react-native';
import Header from './src/components/Header';

// create the component
const App = () => {
  return (
              <Header />
    );
};
// render the component
AppRegistry.registerComponent('ListItem', () => App);

Header.js

import React from 'react';
import { Text } from 'react-native';

const Header = (props) => {
  return(
     <Text > Albums ! </Text>
 );
};

export default Header;

答案 1 :(得分:0)

您提供的错误路径请更正

import Header from './src/components/Header';

import Header from '../src/components/Header';

答案 2 :(得分:-1)

我认为您需要将propsindex.android.js传递到header.js。在原始代码中,您在header.js中设置了const Header = (props) => {,但是你没有在索引文件中传递props

    //import lib
import React from 'react';
import {AppRegistry,View} from 'react-native';
import Header from './src/components/Header';

// create the component
const App = () => {
  return (
       <Header headerText={'Albums'} />
    );
};
// render the component
AppRegistry.registerComponent('ListItem', () => App);

header.js

import React from 'react';
import { Text } from 'react-native';

const Header = (props) => {
  return(
     <Text > {props.headerText} </Text>
 );
};
export default Header;