Closed segevfiner closed 1 year ago
Workaround
pnpm i stream
/** eslint-env node */
import { defineConfig, splitVendorChunkPlugin } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "node:path";
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
stream: resolve(__dirname, "./node_modules/stream/index.js"),
},
},
plugins: [vue(), splitVendorChunkPlugin()],
});
This seems to be fixed in vite@4.3.0-beta.5: https://stackblitz.com/edit/vitejs-vite-6wetst
@patak-dev We are still getting a lot of warnings due to trying to build the Node version in the browser build though. Something is still wrong, it should try to build the browser build and strip it out due to tree-shaking, not build the Node build and strip it out...
We are still getting a lot of warnings due to trying to build the Node version in the browser build though.
@segevfiner
Would you elaborate this part?
@vue/devtools only has main
field and that file uses a runtime detection (typeof window !== 'undefined'
).
https://cdn.jsdelivr.net/npm/@vue/devtools@6.5.0/package.json
https://cdn.jsdelivr.net/npm/@vue/devtools@6.5.0/index.js
So it's expected that the node version gets in the build.
Maybe that's the bit that should be changed though. @vue/devtools itself might be better off using package.json exports instead of runtime detection?
I think so. I'll close this issue as I think it needs to be fixed on the @vue/devtools side.
Should I open an issue on @vue/devtools?
Yes, that would be nice.
Describe the bug
Vite includes
import "emitter"
in the outputted bundle when you have conditional usage of@vue/devtools
(That should be tree shaken out),splitVendorChunkPlugin
and the modulestream
installed transitively.Vite apparently includes chooses to include the node version of
@vue/devtools
in the bundle instead of the browser version. This then includes arequire
to thestream
module, which due to installingpino-datadog
resolved to the npmstream
module, which includes animport "emitter"
which gets included into the final bundle.It doesn't get included without
splitVendorChunkPlugin
. Or some other usages ofmanualChunks
that I wasn't able to pinpoint.Reproduction
https://stackblitz.com/edit/vitejs-vite-u6bnd2?file=src/main.ts
Steps to reproduce
npm run build
in the reproduction.import "emitter"
which will fail at runtime.System Info
Used Package Manager
pnpm
Logs
No response
Validations