2017-05-11 124 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

相關問題