jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.07k stars 218 forks source link

Process shim messing up with iconv-lite from express or body-parser #303

Closed acailly closed 4 years ago

acailly commented 4 years ago

I finally understood a bug I had with iconv-lite (https://github.com/ashtuchkin/iconv-lite) when I was trying to browserify express (https://github.com/expressjs/express) or body-parser (https://github.com/expressjs/body-parser) with a configuration that used BrowserFS

This is an issue for my future me and for everyone that fell in the same trap. Feel free to close it.

These libraries use an old version of iconv-lite (0.4.24) which load streams or not depending on the snippet contained in this issue: https://github.com/ashtuchkin/iconv-lite/issues/202

You can see it loads streams if process.versions.node is defined, and it is usually undefined when bundling with browserify or webpack.

Except if we use BrowserFS and its shim for process, then process.versions.node become defined and it tries to load streams (and fail).

The workaround I found is to add the following line in the first lines of your app:

process.versions.node = undefined // to fix the iconv-lite error with streams

I haven't tested it extensively so I don't know if it causes more bugs.

If you have a better solution, tell me! :smiley:

acailly commented 4 years ago

maybe somewhat related to https://github.com/ashtuchkin/iconv-lite/issues/204