【问题标题】:Unable to include 3rd party node-modules in React native application无法在 React 本机应用程序中包含 3rd 方节点模块
【发布时间】: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


    【解决方案1】:

    对打包程序的回归是introduced in React Native 0.39。尝试重新启动打包服务器。 如果这没有帮助,请按照错误描述中的说明进行操作:

    1. 清除守望者手表:watchman watch-del-all
    2. 删除node_modules文件夹:rm -rf node_modules && npm install
    3. 重置打包程序缓存:rm -fr $TMPDIR/react-*npm start -- --reset-cache

    import 就像现代 (es2015) 版本的 require

    【讨论】:

    • "我什么都试过了。反馈中的所有建议,我什至尝试全局安装 node-craigslist:"谢谢,但这些都不起作用。
    • 如果您使用的是 linux,请尝试同时从 /tmp 中删除 react-native*rm -rf /tmp/react-native*
    猜你喜欢
    • 2020-08-16
    • 2021-08-21
    • 2020-11-07
    • 1970-01-01
    • 2022-01-08
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    相关资源
    最近更新 更多