-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Node stream polyfill not working #1915
Comments
In general Vite does not try to support libraries that explicitly expect Node built-ins to be available in the browser. i.e. making Node libs run in the browser is explicitly a non-goal. The lib you are using likely depends more than just a Stream shim, but as said, you'll have to figure that out yourself or stick to webpack. |
One of the main motivations for doing this change is that jsonld-streaming libraries don't work properly with Vite. More info: vitejs/vite#1915
@yyx990803 just FYI, |
@pkit I don't know exactly why, but webpack 4 worked for me on the repository I linked in my original text. I haven't tried with webpack 5. My theory was that webpack used an internal polyfill, but if you tell me it's using the same one then I have no idea what's going on 🙃. |
Describe the bug
I've been trying to use a 3rd party library (jsonld-streaming-parser) with Vite and I haven't been able to make it work. I think the problem is that it's using node's
stream
API which is missing in the browser, so I've tried to replace it withstream-browserify
to no avail (It may be related with browserify/stream-browserify#25, I'm not sure).With webpack v4 it works out of the box, and I think that's because webpack bundles a
stream
polyfill by default.Reproduction
Here's a reproduction of the issue in a small repo (only using Vite and the 3rd party library): https://github.com/NoelDeMartin/vite-sandbox
In case it's useful, here's the same code using webpack to bundle the library and writing the same code in Vite, which works as expected: https://github.com/NoelDeMartin/vite-sandbox/tree/webpack-bundle
System Info
vite
version: vite/2.0.0-beta.65 linux-x64 node-v12.20.0Logs (Optional if provided reproduction)
The error happens in the browser, serving doesn't throw any errors. It throws
TypeError: Stream is undefined
on this line.Note: It also failed trying to use
global
and I fixed it by runningwindow.global = window
before importing the library.The text was updated successfully, but these errors were encountered: