ApeironTsuka / node-webpmux

A mostly 1:1 re-implementation of webpmux as a Node module in pure Javascript. Only thing currently missing is a command-line version.
GNU Lesser General Public License v3.0
26 stars 8 forks source link

Cannot build in nextjs #25

Open FredHappyface opened 11 months ago

FredHappyface commented 11 months ago

Hi I've gone down a massive rabbit hole and the dependency of fs means that I cannot get this to run in the browser

image

Would you be able to add support for this?

Thank you :)

ApeironTsuka commented 11 months ago

It does already support using it in a browser via a sorta-hack (see io.js [1]). However, I don't know anything about NextJS so I don't know how to flag fs as optional (or however it would work for NextJS).

[1] Checking for typeof window === 'undefined' was the "recommended" way I had found for detecting a browser vs NodeJS. Have never been happy with that method.

FredHappyface commented 11 months ago

Ah that makes sense and yeah I'm not to sure how next js works to be honest. I'll have a play around/ google and see if I can find anything useful!

Might be that there's a cross platform option that can be used in-place of fs?

ApeironTsuka commented 11 months ago

I don't know if there's a browser version of fs that does anything (maybe as a GET/POST in the background..?) and especially that's stand-alone (I prefer as few dependencies as possible). The way it works right now is by detecting it's running in a browser and stubbing the fs functions used so that they throw an error if they're called. My intent was that only buffers would be supported in the browser, so that the dev using it can decide where those buffers come from.