runk / node-chardet

Character encoding detection tool for NodeJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`chardet` throws browser error in Electron

GilgameshxZero opened this issue · comments

I opened a similar issue a while ago, but didn't have the time to follow-up then.

I'm working on resolving a bug in museeks, an Electron application. The bug seems to be caused by chardet thinking that the Electron environment is a browser and thus throwing the "File system is not available" error via the "browser" redirect in package.json.

However, the Electron application is running on a desktop environment, and I'd like to keep using chardet for encoding detection if possible. I'm not sure what the best way to go about this is—it seems like there isn't an easy way to special-case Electron (hybrid) environments in configuration.

Not sure if it can help, but the target for the bundle for the UI of the electron app is Webpack's electron-renderer (and not web).

https://webpack.js.org/configuration/target/#target

I guess it means this magic spell does not do the trick:

"./lib/fs/node.js": "./lib/fs/browser.js"

.. or another likely scenario is filesystem is really not available if you get this error from

throw new Error('File system is not available');

I'll try to reproduce this error to narrow down the issue.

Thank you so much for looking into it and even submitting a PR @runk 🙌

@GilgameshxZero this can be closed

Thanks for handling this @runk !