philikon / ReactNativify

How to use node.js libraries in React Native
242 stars 23 forks source link

What package would you recommend for node's fs? #1

Closed chaodoze closed 7 years ago

chaodoze commented 8 years ago

In particular, fs.readFileSync() - many node packages use that to read a local, say config, file.

philikon commented 7 years ago

There's absolutely no way to make synchronous disk I/O work in React Native. You could probably polyfill the async methods in fs by writing your own Native Module, and then aliasing that to fs using babel-plugin-rewrite-require, as demonstrated here. If you get that working, please do send a PR, I'd be happy to include it in ReactNativify as an example.

That said, if you're relying on a third party package that reads a configuration file from disk synchronously, you should really ask yourself if you want to be reusing that code in React Native. It might be easier to rewrite it yourself, patch it to not do that, or to give it a fake fs module that will actually read the data from a place in memory, where you've been able to populate it.