首页 文章

反应原生的节点模块

提问于
浏览
0

我只是尝试将一些节点模块添加到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

当我使用"non-react modules"的命令链接时,我仍然一无所获:
enter image description here

此外,当我只是尝试添加此模块时:

  • import 'first-image-search-load'

  • import {saveFirstImage} from 'first-image-search-load'

  • import * from '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我得到:
enter image description here

开发服务器返回响应错误代码:500 URL:http://10.0.2.2:8081 / index.android.bundle?platform = android&dev = true&hot = false&minify = false正文:{“message”:“无法解析模块https来自/Users/Pien/Projects/smog_bielsko/node_modules/node-google-image-search/index.js:模块映射或这些目录中不存在模块:\ n / Users / Pien / Projects / smog_bielsko / node_modules / node-google-image-search / node_modules \ n,/ Users / Pien / Projects / smog_bielsko / node_modules \ n \ n这可能与https://github.com/facebook/react-native/issues/4968\n有关尝试以下方法:\ n 1.清除守望者 Watch :watchman watch-del-all . \ n 2.删除node_modules文件夹:rm -rf node_modules && npm install . \ n 3.重置包装器缓存:rm -fr $ TMPDIR / react- *或npm start - --reset-cache . “,”name“:”UnableToResolveError“,”type“:”UnableToResolveError“,”errors“:[{}]} onResponse DevServerHelper.java:323执行RealCall . java:126运行NamedRunnable.java:32 runWorker ThreadPoolExec utor.java:1113运行ThreadPoolExecutor.java:588运行Thread.java:818

请告诉我如何将正常的npm插件导入到react-native中 .

谢谢

3 回答

  • 1

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

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

  • 0

    关于Big Rich提供的答案的一些其他信息 .

    我认为通过应用ReactNativify填充方法可以解决您遇到的错误 . 否则,错误会提到缺少的Node API对象 .

    但是如果您的 first-image-search-node 包是为Node编写的,并且您确实想要使用ReactNativify,那么您应该注意一些其他问题,我在此处记录了这些:

    Can we use nodejs code inside react native application?

    简而言之,它强调:

    • 将变换器分成2个文件的方法 .

    • 建议使用'babel-plugin-module-resolver'

    • .babelrc 中写下所有垫片替换,而不是js代码

    • 即使你有 transformer.js 也应该包含一个根 .babelrc

  • 1

    你不要使用本机代码 . 对于只有js的库,您需要做的就是 npm install packageName . 如果库有任何html / css / dom内容,那么它将无法与react native一起使用 .

相关问题