我只是尝试将一些 Node 模块添加到 react-native 中。
我发现它只适用于 react-native modules和 react-native link
该模块。
我想使用: - https://www.npmjs.com/package/node-google-image-search 或者 - https://www.npmjs.com/package/first-image-search-load
当我将命令链接与“非 react 模块”一起使用时,我仍然一无所获:
此外,当我试图通过以下方式添加此模块时:
import 'first-image-search-load'
从“first-image-search-load”导入 {saveFirstImage}
从 'first-image-search-load' 导入 *
var first-image-search-load = require('first-image-search-load');
var first-image-search-load = require('./first-image-search-load');
var first-image-search-load = require('./node-modules/first-image-search-load');
然后尝试将它们放入 index.android.js 我得到:
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 thenode_modules
folder:rm -rf node_modules && npm install
.\n 3. Reset packager cache:rm -fr $TMPDIR/react-*
ornpm 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/