I'm getting this build error with vite and sveltekit using adapter-node
I'm not sure why it won't build since it relies on node to server the client.
dev works fine
'Buffer' is not exported by __vite-browser-external:buffer
I tried polyfills but they don't work.
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
webworkers: true,
}),
NodeModulesPolyfillPlugin()
]
}
},
build: {
minify: true,
rollupOptions: {
plugins: [
// Enable rollup polyfills plugin
// used during production bundling
rollupNodePolyFill()
]
}
}
I got this error without using polyfill. Fixed it with:
npm install -D buffer
// vite.config.js
build: {
commonjsOptions: {
include: ['node_modules/buffer/index.js']
}
}
This is related to a reported issue on vite https://github.com/vitejs/vite/issues/3024
Or if you need to apply this to all .js
dependencies:
// vite.config.js
build: {
commonjsOptions: {
include: ['node_modules/**/*.js']
}
}