【发布时间】:2017-01-16 17:26:25
【问题描述】:
我正在尝试了解如何将节点模块导入或要求(不确定是哪个!但我都尝试了相同的结果)节点模块到我的 react-native 项目中。
具体来说,我正在尝试包含 node-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 文件夹中。所以我不确定我做错了什么。
如何将节点模块包含到 React Native 应用程序中?
在这种情况下,require 和 import 有什么区别?
如何将 node-craigslist 包含到 react 本机应用程序中而不会出错?
【问题讨论】:
标签: module npm react-native