davidmyersdev / vite-plugin-node-polyfills

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

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

Open ii02735 opened 2 months ago

ii02735 commented 2 months ago

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

I have the following error :

image

My setup

You can find a minimal reproductible example there : https://github.com/ii02735/vite-minify-xml-bug-build

jsudung commented 1 month ago

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.