React Native:无法解析模块 fs [英] React Native: Unable to resolve module fs

查看:112
本文介绍了React Native:无法解析模块 fs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unable to resolve module fs from /...mypath

我在尝试将节点模块导入我的 react-native 应用程序时遇到此错误.

I got this error when trying to import a node module into my react-native app.

模块以这种方式使用了'fs':

The module used 'fs' in this way:

var fs = require('fs');
var list = JSON.parse(fs.readFileSync(__dirname + '/list.json', 'utf8'));

推荐答案

React Native 应用程序不在 Node.js 环境中运行(它仅由打包程序用于实际服务和编译您的应用程序包).

React Native applications do not run in the Node.js environment (it is only used by the packager to actually serve and compile your application bundle).

由于您的应用在 iPhone 或 Android 上的 JS VM 中运行,因此访问文件系统的唯一方法是使用 react-native-fs 或任何其他利用桥接连接与平台特定本机 API 对话的第三方模块.

Since your app is running inside JS VM on either iPhone or Android, the only way to access filesystem is to use react-native-fs or any other 3rd party module that utilises bridge connection to talk to the platform specific native APIs.

这篇关于React Native:无法解析模块 fs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆