2017-03-07 119 views
0

我的目錄結構是這樣的:在導入文件陣營本地

web/ 
    js/ 
    Test.js 
mobile 
    index.android.js 

index.android.js,我加import Test from '../web/js/Test。不過,我得到這個錯誤:

(node:590) UnhandledPromiseRejectionWarning: 
Unhandled promise rejection (rejection id: 12): 
UnableToResolveError: 
Unable to resolve module `../web/js/Test.js` from `/mnt/d/.../mobile/index.android.js`: 
Directory /mnt/d/.../web/js/Test.js doesn't exist 

我試圖重新運行react-native start,它仍然沒有工作。我沒有安裝Watchman,但我不認爲這是問題。

+0

我不知道你在試着克去做。您是否試圖在React Native中重複使用您的React網頁代碼? React Native是否允許您從項目根目錄及其嵌套文件夾以外的任何位置導入js文件?看起來你似乎錯過了你提到的導入的單引號,儘管這可能是你的錯誤。另一個問題是如何定義測試。您是否正確導出該組件?我們需要更多信息來確定發生了什麼。 – nbkhope

回答

0

1)在移動文件夾的package.json添加作爲依賴性:

"dependencies": { 
    //...your deps here + 
    "commonWebAndMobileDeps": "file:../web/js/common" 
} 

2)確保Test.js是在web/js/common

3)在移動文件夾運行npm install

4 )在移動導入它與:

import Test from 'commonWebAndMobileDeps/Test'