Browserify with require('fs')

前端 未结 5 1118
感动是毒
感动是毒 2020-11-28 11:24

I was trying to use browserify on a file that uses the fs object. When I browserify it, the call to require(\'fs\') doesn\'t get transformed and require

5条回答
  •  -上瘾入骨i
    2020-11-28 11:54

    Which filesystem should the browser use then? The HTML5 filesystem is not really comparable to a traditional filesystem. It doesn't have symlinks, and it is only accessible asynchronously outside Web Workers.

    So the answer is: Write an abstraction layer yourself that can rely on the fs module when running in Node.js, and the HTML5 FS API when running in the browser. The differences are too large to have browserify translate for you.

提交回复
热议问题