2017-01-16 79 views
1

我在嘗試瞭解如何導入或需要(不確定哪個!但我已嘗試使用相同的結果)node-modules到我的react-native項目。無法在React本機應用程序中包含第三方節點模塊

具體來說,我試圖包含節點craigslist。

我遇到了以下錯誤:

(node:82382) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2491): UnableToResolveError: Unable to resolve module url from /Users/fogonthedowns/hack/js/react-native/AwesomeProject/node_modules/node-craigslist/dist/index.js: Module does not exist in the module map or in these directories: 
    /Users/fogonthedowns/hack/js/react-native/AwesomeProject/node_modules 
, /Users/fogonthedowns/node_modules 

This might be related to https://github.com/facebook/react-native/issues/4968 
To resolve try the following: 
    1. Clear watchman watches: `watchman watch-del-all`. 
    2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`. 
    3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`. 

我的反應的版本是:

~/hack/js/react-native/AwesomeProject$ react-native --version 
react-native-cli: 2.0.1 
react-native: 0.40.0 

我index.ios.js是here

我試過了一切。反饋中的所有建議,我甚至嘗試過在全球安裝node-craigslist:

npm install -g node-craigslist 

然後從頭開始重建。 node-craigslist顯然包含在我的node-modules文件夾中。所以我不確定我做錯了什麼。

如何將節點模塊包含到反應本機應用程序中?

在這種情況下,require和import有什麼區別?

如何將node-craigslist包含到反應本機應用程序中而沒有錯誤?

回答

0

對包裝商的迴歸是introduced in React Native 0.39。嘗試重新啓動打包程序服務器。 如果這將不利於然後按照指示,從錯誤描述:

  1. Clear watchman watches: watchman watch-del-all .
  2. Delete the node_modules folder: rm -rf node_modules && npm install .
  3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache .

import來說就像require現代(ES2015)版本。

+1

「我已經試過了所有的東西,在反饋中的所有建議,我甚至嘗試過在全球範圍內安裝node-craigslist:」謝謝,但這些都不起作用。 –

+0

如果您使用的是linux,請嘗試從'/ tmp'中刪除'react-native *':'rm -rf/tmp/react-native *' – farwayer

相關問題