3

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();
           });
        });
    }
 }
Val
  • 17
  • 4
wlbreath
  • 31
  • 1
  • Possible duplicate of [Browserify with require('fs')](http://stackoverflow.com/questions/16640177/browserify-with-requirefs) – Mark Stosberg Apr 18 '16 at 17:58

1 Answers1

1
import * as fs from 'fs';

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

Dan H
  • 3,524
  • 3
  • 35
  • 46
  • I have solved the problem, thank you for your answer. The problem is caused as I guessed. The Electron has a default global "require“ which conflicts with the browserify's "require" – wlbreath Apr 19 '16 at 06:52
  • @wlbreath How did you solve the problem ? I am having the exact same problem right now.. – grahan Dec 20 '16 at 17:50