Closed tb-viktor closed 3 weeks ago
Start a new pull request in StackBlitz Codeflow.
I faced the same issue all day long for a production build (was ok on dev). I think it’s because of some chunk mixing.
I found a solution: make the aliased dependency its own chunk
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes("three165")) {
return "three165";
}
},
},
},
This was caused by #16068. The behavior change is expected.
This file imports three.js by three
.
https://github.com/mrdoob/three.js/blob/5a8328736ca7207f386254f88ddb795d396877db/examples/jsm/loaders/3DMLoader.js#L27
Before #16068, that resolved to node_modules/three
because node_modules/three
is a phantom dependency of node_module/three165
. If you use a package manager that avoids the phantom dependency problem like pnpm, you can see that it won't work.
After #16068, three
is now treated as a self-referencing import and resolves to node_module/three165
. That causes two three.js to be served / bundled.
For your case, adding resolve.alias
like below should work.
import path from 'node:path'
import url from 'node:url'
const _dirname = path.dirname(url.fileURLToPath(import.meta.url))
export default defineConfig({
resolve: {
alias: {
'three': path.resolve(_dirname, './node_modules/three/build/three.module.js')
}
},
})
Closing as this is not a bug.
Describe the bug
Hey everyone,
We're experiencing a regression with how npm package aliases seem to be handled by Vite in versions after
5.1.6
. We waited for a while thinking that it's a bug that would be resolved soon, but even with the latest version of Vite this still happens, so I am opening this issue about it.In our product we have a setup where we are temporarily using two
three
versions via npm package aliases, since we have to use a loader from a newer version to load 3DM files:And the resulting code:
This used to work fine in
5.1.6
, and the loader would correctly load and render the file, but since upgrading to5.2.0+
something goes wrong and the model does not load correctly anymore. I've made a minimal reproduction on stackblitz using the react-ts starter. The reproduction steps are also provided.Initially this only happened for us with production bundles (
npm run build
->npm run preview
), but on stackblitz, it seems to also happen during development. On the plus side, this makes debugging easier.Any idea what is going wrong?
Reproduction
https://stackblitz.com/edit/vitejs-vite-y54j6h?file=package.json
Steps to reproduce
npm install vite@5.2.0
, thennpm run dev
System Info
Used Package Manager
npm
Logs
No response
Validations