Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Unable to resolve module fs

Tags:

Unable to resolve module fs from /...mypath 

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

The module used 'fs' in this way:

var fs = require('fs'); var list = JSON.parse(fs.readFileSync(__dirname + '/list.json', 'utf8')); 
like image 555
C.Lee Avatar asked Aug 19 '16 19:08

C.Lee


1 Answers

I ended up using 'rn-nodeify' to include fs into React Native. You can use most of the node core modules this method. Install it with npm:

npm install rn-nodeify 

Then in package.json file, add the following line in "scripts" to specify which modules you want to include in your RN project. For example, I used fs, crypto and https, and the line goes

"postinstall": "node_modules/.bin/rn-nodeify --install crypto,fs,https --hack" 
like image 127
C.Lee Avatar answered Oct 23 '22 23:10

C.Lee