Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer works in browser with Webpack 5 #52

Open
eddie-dunn opened this issue Dec 21, 2021 · 2 comments
Open

No longer works in browser with Webpack 5 #52

eddie-dunn opened this issue Dec 21, 2021 · 2 comments

Comments

@eddie-dunn
Copy link

Webpack 5 no longer provides polyfills for NodeJS packages. In my case I get Uncaught ReferenceError: process is not defined from this line. I.e., it's process.platform that fails.

I'm running an app built with Create React App, which is why I think the previous line referencing process.env seems to work.

@doowb
Copy link
Owner

doowb commented Dec 21, 2021

Is there a way to add the polyfill?

This issue may be related and might get fixed in create-react-app.

@eddie-dunn
Copy link
Author

Not sure, I haven't had the time to look into it much. Here's an answer on Stack Overflow: https://stackoverflow.com/a/65018686/955014

A simpler solution could be to just wrap the assignments of isWindows and isLinux in a try-catch, where you default to something sensible on error.

Though as I see it, I'm not sure querying process.platform and then hardcoding the behavior based on that is the best solution. For example, the reason I'm using ansi-colors in a web app is for communication with an external device via the Web Serial API. In that regard, process.platform is not useful at all, since it only applies to the host OS, not the one being communicated with. A solution where it's possible to configure the lib during runtime whether it should use Windows or Linux ANSI seems a lot more flexible to me.

Or, perhaps web and ANSI-colored text streams from external devices is not something you wish to support, which is fine too, and then I suppose you can leave it as is :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants