Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browserify load fs return empty object

I'm new to Electron, I use react to build my application, and I use browserify to compile jsx to js and es6 to es5, but when I use import to add the fs module( import fs from "fs" ), it return a empty object. I guess I it may be the compiled file uses browserify's "require" to load module fs rather than node's "require". And when load the fs module, browserify return a empty object directly. how can i solve this problem:joy:

import fs from 'fs';

class MyFS {

    static mkdir(path, mode){
        mode = mode || 0o777;

        return new Promise(function(resolve, reject){
           fs.mkdir(path, mode, function(err){
               if(err){
                   reject(err);
                   return;
               }

               resolve();
           });
        });
    }
 }
like image 685
wlbreath Avatar asked Mar 01 '26 08:03

wlbreath


1 Answers

import * as fs from 'fs';

The module may not have a default export, so give that a shot.

like image 105
Dan H Avatar answered Mar 02 '26 23:03

Dan H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!