vite-plugin-node-polyfills icon indicating copy to clipboard operation
vite-plugin-node-polyfills copied to clipboard

Bug: PassThrough is not exported by "__vite-browser-external" during build

Open ii02735 opened this issue 1 year ago • 1 comments
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 :

image

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

ii02735 avatar Apr 07 '24 05:04 ii02735

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.

jsudung avatar May 31 '24 05:05 jsudung