我正在尝试了解如何导入或要求(不确定哪个!但我已尝试使用相同的结果)节点模块进入我的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文件夹中。所以我不确定我做错了什么。
如何将节点模块包含在反应原生应用程序中?
在这种情况下,require和import有什么区别?
如何在没有错误的情况下将node-craigslist包含到react本机应用程序中?
答案 0 :(得分:0)
回归是introduced in React Native 0.39给打包者。尝试重启打包服务器。 如果这样做无效,请按照错误说明中的说明进行操作:
- 清除守望者手表:
watchman watch-del-all
。- 删除
node_modules
文件夹:rm -rf node_modules && npm install
。- 重置打包程序缓存:
醇>rm -fr $TMPDIR/react-*
或npm start -- --reset-cache
。
import
就像现代(es2015)版require
。