2017-10-09 73 views
0

我有AA RN的应用程序(RN版本0.48.3),我的文件夹结构:阵营本地导入路径快捷方式的问题

/index.ios.js 
/index.android.js 
/app/index.js 

index.ios.js:

import {AppRegistry} from 'react-native'; 
import home from './app'; 
AppRegistry.registerComponent('home',() => home); 

/应用/ index.js:

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

export default class home extends Component { 
    render() { 
    return (
     <View> 
    ... 
     </View> 
    ); 
    } 
} 

如果我运行的应用程序,它显示了我这个错误:

Element type is invalid: expected a string (for Built-in components) or a class/Object...

但是,当一个变化index.ios.js第二线是否能够正常工作:

import home from './app'; -> import home from './app/index.js'; 

任何人都可以向我解释为什么? “./app”路径在index.js里面不正确?

回答

1

尝试与驼峰主页,并从你的类名除去家里

瞧:

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

export default class extends Component { 
    render() { 
    return (
     <View> 
    ... 
     </View> 
    ); 
    } 
} 



import {AppRegistry} from 'react-native'; 
    import Home from './app'; 
    AppRegistry.registerComponent('Home',() => Home); 
+0

同样的错误......,如果我从” ./app改变与进口首页路径才起作用/index.js';它不是一个问题,但我想知道为什么... –

+0

我的解决方案工作? 当你把./app放在一个节点上时,你需要使用module.export对象中的annomye元素,在你的情况下你已经指定了一个名字,而导出的默认值不需要名称,如果你想要做什么没有。这里有一个例子:{Home}和导出类Home ... –

+0

谢谢,但是我对你的解决方案有同样的错误,似乎无法得到路径“./app”,但只能使用“./app/index。 JS“的工作... –