React Native-使用依赖于node.js核心模块的Javascript模块

React-Native - Using a Javascript Module that relies on node.js core module

本文关键字:模块 核心 Javascript js node Native- 依赖于 React      更新时间:2023-09-26

我试图使用用Javascrip编写的vcard解析模块,但它依赖于node.js核心模块、fs和path。我的应用程序是用React Native编写的。有人建议我如何模拟npm的文件系统和路径模块,以便在vcard解析javascript模块中使用吗?

有问题的文件是vcards-js的索引文件,位于应用程序的node_modules文件夹中。所以app/nod_module/vcards js/index.js

var fs = require('fs');
var path = require('path');

我分叉vCards JS用于React Native:https://github.com/idxbroker/vCards-js/tree/react-native

我没有尝试一对一地模拟fs,而是使用了一个包:react native fs其方法和功能与等效节点非常相似。vCards JS只需要最少的调整。

请随意使用此版本。

npm install react-native-vcards@https://github.com/idxbroker/vCards-js.git#react-native --save