无法导入反应原生自定义模块

问题描述:

我正在使用原生反应ES6。 没有编译时错误,也没有运行时错误。 我试图导入一个主模块,但我没有任何错误。以下是Main.js文件的代码:无法导入反应原生自定义模块

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

class Main extends Component { 
    render() { 
    return (
     <View style={{justifyContent:'flex-start', marginTop: 120}}> 
     <Text style={{fontSize:20}}> Testing the router</Text> 
     <Text> Testing the router</Text> 
     </View> 
    ); 
    } 
} 

module.exports = Main; 

这是我的第一个项目文件。我正在尝试导入Main.js文件。

'use-strict'; 
import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View, 
    NavigatorIOS 
} from 'react-native'; 
import Main from './Main.js'; 

export default class FirstProject extends Component { 
    render() { 
    return (
     <NavigatorIOS 
     initialRoute={{ 
      title: 'App Title', 
      component: Main 
     }} /> 
    ); 
    } 
} 

AppRegistry.registerComponent('FirstProject',() => FirstProject); 
+0

确保您的路径是正确的inculde main.js – Moorthy

Node.js样式的单值导出不起作用。在那里,你导出的对象,而不是单个值:module.exports = Main

将其更改为module.exports.Main

更好的语法是使用export default Main

+0

的问题是在反应本地,但不是在node.js – coolly

+0

@coolly当然,反应原生:)我说** Node.js样式**将不起作用 – taha

+0

@coolly如果这个答案不解决您的问题,请让我知道(所以我可以删除它)不相关的答案应该被删除 – taha