Not working with 'stream'

#5 · closed · 4 comments

View on GitHub ↗

krokben

Hi, I'm trying to set up a React project with Vite. Even after using your adapter with the `stream` package, the code still faces a runtime error where it says stream is undefined. Maybe I'm doing something wrong? This is my `vite.config.ts`: ``` import { defineConfig } from 'vite'; import assert from 'assert'; import stream from 'stream'; import browserifyAdapter from 'esbuild-plugin-browserify-adapter'; import react from '@vitejs/plugin-react'; import EnvironmentPlugin from 'vite-plugin-environment'; import tsconfigPaths from 'vite-tsconfig-paths'; export default defineConfig({ envPrefix: 'REACT_APP_', plugins: [ browserifyAdapter(assert, stream), react(), EnvironmentPlugin('all', { prefix: 'REACT_APP_' }), tsconfigPaths(), ], }); ```

Comments

m90

I have to admit that from looking at your code snippet I am not entirely sure what you're trying to do. Neither `stream` nor `assert` are browserify transforms, so I don't really know what you expect to happen in that case. What exactly would you like to happen when you pass `assert` and/or `stream` and want to use them as an esbuild plugin? A browserify transform usually is a function `transform(filepath, options)` that returns a through stream. Any such function should work using this tool: https://github.com/m90/esbuild-plugin-browserify-adapter/blob/5206f9a0b9072fd322b0580355f88f62a622d98d/index.js#L16-L18

krokben

Hi @m90, sorry I must've misunderstood how it works. We have this app that uses a library that internally uses `stream`, and after I moved to a Vite config from create-react-app, it lost all of the native node packages in the browser. So therefore `stream` is undefined in that package and throws a runtime error. Am I on the right path to use your library to solve this?

m90

Unfortunately this is not what this package is good for. What it does is let you re-use a browserify transform as an esbuild plugin, but this is not what you're trying to do apparently. Maybe `node-modules-polyfill` helps: https://github.com/remorses/esbuild-plugins

krokben

Ok thank you for help!