I resolved this using Vite config’s optimizeDeps.exclude
!
// ...
optimizeDeps: {
exclude: [
'three', // to prevent Vite's code chunking which causes an error
],
esbuildOptions: {
target: 'esnext', // Three.js uses top-level await
},
},
// ...