简体   繁体   English

在React-Native中为NPM导出NativeModules

[英]Export NativeModules for NPM in React-Native

I'm trying to create a node module from my React Native App. 我正在尝试从我的React Native App创建一个节点模块。 The problem is, that the module is mostly a NativeModule. 问题在于,该模块主要是NativeModule。 So my index.js looks like this: 所以我的index.js看起来像这样:

 import { NativeModules } from 'react-native'; export default NativeModules.MyNativeClass; 

When i install my package to my node_modules (inserted local relative path to package.json) and import it to my JS file, it's always undefined. 当我将程序包安装到node_modules(插入package.json的本地相对路径)并将其导入到我的JS文件时,它始终是未定义的。 I tried to export a test object, like export default {test:'test'}; 我尝试导出测试对象,例如export default {test:'test'}; and it works. 而且有效。 So, is it possible to export the Native Module through node_modules? 因此,是否可以通过node_modules导出本机模块?

If anyone is stuck to the same issue. 如果有人坚持同样的问题。 Just link it with 只需链接

react-native link 反应本机链接

and your native modules from your node_modules get visible. 并且来自node_modules的本机模块将可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM