vite-plugin-node-polyfills
vite-plugin-node-polyfills copied to clipboard
Bug: PassThrough is not exported by "__vite-browser-external" during build
trafficstars
Summary
In a project, I use the following dependency : https://www.npmjs.com/package/minify-xml
Because it is a dependency written for a pure NodeJS project, I had to use polyfills like this :
import { defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
export default defineConfig({
plugins: [nodePolyfills({
include: ['_stream_passthrough', 'util']
})]
})
What I expect
Everything should work in dev mode, or when I build the project.
What I got
- In dev mode, everything is working ✅
- When I try to build the project, it fails 💥
I have the following error :
My setup
- Vite v5.
- Windows 11
- NodeJS v20.9.0
You can find a minimal reproductible example there : https://github.com/ii02735/vite-minify-xml-bug-build
Passthrough is imported from stream. So have you tried importing stream instead of _stream_passthrough?
Also try setting protocolImports: true, since it is importing Passthrough from node: protocol import.
I encountered the same issue and this fixed it for me.