2017-05-11 96 views
2

我有一个非常简单的React Native项目,我正在努力工作。这是一个iOS项目,简单地将RCTRootView添加到UIViewController。当我打的网址从网络浏览器,我得到:反应本机:无法解决模块

Unable to resolve module `/src/components/HelloReact` from `/Users/myusername/Desktop/DemoReact/index.ios.js`: Directory /src/components/HelloReact doesn't exist. 

index.ios.js

'use strict'; 

import { AppRegistry } from 'react-native'; 
import HelloReact from '/src/components/HelloReact'; 

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

HelloReact.js

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

export default class HelloReact extends Component { 
    render() { 
    return (
     <Text style={{fontWeight: 'bold'}}> 
     I am bold 
     <Text style={{color: 'red'}}> 
      and red 
     </Text> 
     </Text> 
    ) 
    } 
} 

我很茫然如何解决这个问题。我已经尝试了所有的以下内容:

  • npm start
  • npm start --reset-cache
  • 删除node_modules目录并重新安装
  • 卸载并重新安装节点,更夫,反应本地的,和NPM
  • 试戴物理设备和模拟器

有没有人看到我的代码中有任何错误或知道这个问题可能是什么?我愿意通过电子邮件或电话来解决这个问题。我越来越绝望。

回答

5

import HelloReact from '/src/components/HelloReact';搜索模块中的绝对路径,而不是相对于当前(RN的应用程序目录),因此氡无法找到(如不存在的话)

将其更改为import HelloReact from './src/components/HelloReact';

+0

哇!我好蠢。这工作!非常感谢!运行应用程序时仍然存在另一个问题,但我将编辑此问题并重新发布一个新问题。 – tentmaking

+0

Gald帮助;)确保将它标记为答案,如果它有帮助。^_^ –

+0

我会尽快将它标记为答案!非常感谢。下一个问题是! – tentmaking

相关问题