davidmyersdev / vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments.
MIT License
314 stars 23 forks source link

Bug: process polyfill causes issues by virtue of being an ES module #106

Open WasabiThumb opened 2 months ago

WasabiThumb commented 2 months ago

Summary

Cross-post of readable-stream #539 (for which a reproducible example was made, also on GitHub Pages) May be related to #98.

This may not chiefly be an issue with vite-plugin-node-polyfills, but it has been observed that in combination with readable-stream and vite that the process polyfill causes errors due to being used as if it is not an ES module, or conversely, not having its default export properly unwrapped. The purpose of this issue is to hopefully help narrow down the code that could least intrusively be updated to fix this incompatibility, for instance (and not primarily), changing vite-plugin-node-polyfills to export a CJS shim via export = process in addition to a default export¹.

¹ Something like (and attempt to fight the urge to vomit) this:

export = Object.assign(process, { process, default: process })

Any insight, especially on how Vite handles ES module interop in combination with this plugin, would be greatly appreciated. :heart:

davidmyersdev commented 1 month ago

Repro: https://stackblitz.com/~/github.com/WasabiThumb/reprex-539