javascript - react-native 中的 Node 模块

标签 javascript node.js reactjs react-native

我只是尝试将一些 Node 模块添加到 react-native 中。 我发现它只适用于 react-native modulesreact-native link 该模块。

我想使用: - https://www.npmjs.com/package/node-google-image-search 或者 - https://www.npmjs.com/package/first-image-search-load

我试过: Link1 Link2 Link3 Link4

当我将命令链接与“非 react 模块”一起使用时,我仍然一无所获: enter image description here

此外,当我试图通过以下方式添加此模块时:

  1. import 'first-image-search-load'
  2. 从“first-image-search-load”导入 {saveFirstImage}
  3. 从 'first-image-search-load' 导入 *
  4. var first-image-search-load = require('first-image-search-load');
  5. var first-image-search-load = require('./first-image-search-load');
  6. var first-image-search-load = require('./node-modules/first-image-search-load');

然后尝试将它们放入 index.android.js 我得到: enter image description here

The development server returned response error code: 500

URL: http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false

Body: {"message":"Unable to resolve module https from /Users/Pien/Projects/smog_bielsko/node_modules/node-google-image-search/index.js: Module does not exist in the module map or in these directories:\n /Users/Pien/Projects/smog_bielsko/node_modules/node-google-image-search/node_modules\n, /Users/Pien/Projects/smog_bielsko/node_modules\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: watchman watch-del-all.\n 2. Delete the node_modules folder: rm -rf node_modules && npm install.\n 3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache.","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]} onResponse DevServerHelper.java:323 execute RealCall.java:126 run NamedRunnable.java:32 runWorker ThreadPoolExecutor.java:1113 run ThreadPoolExecutor.java:588 run Thread.java:818

请告诉我如何将普通的 npm 插件导入 react-native..

谢谢

最佳答案

实际上,ReactNativify项目应该做到这一点,让我们在 React-Native 代码项目 (RN) 中使用 NodeJS 模块。

在我撰写本文时,2017 年 5 月,project seems to not work with RN versions 0.43.3+, due to breaking changes .

关于javascript - react-native 中的 Node 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42768221/

相关文章:

javascript - 单击颜色更改 - bool 值

javascript - 使用按钮从 XML 中检索数据

javascript - 当包含 NPM 包时,Meteor.js 中的“require is not defined”

reactjs - 在 react-Native 中创建 UI 时 Class 和 Const 有什么区别?

javascript - 我可以在不渲染的情况下沿 SVG 路径获取点吗?

javascript - 如何在 NEXT JS 中的路由之间传递状态?

javascript - Phonegap无法读取本地音频文件

javascript - jQuery - 数字格式的小片段无法按预期工作

node.js - NodeJS : Adding channels to a Socket. IO服务器无需重启

node.js - npm 安装错误 - MSB3428 : Could not load the Visual C++ component "VCBuild.exe"