vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.1k stars 6.03k forks source link

Generated an empty chunk: "lodash-unified" #17694

Closed bushuizaijian closed 2 weeks ago

bushuizaijian commented 1 month ago

Describe the bug

1721109480181 1721109323481

After adding the manualChunks configuration, the packaging will display the described content

Reproduction

https://stackblitz.com/edit/vitejs-vite-cdt85l?file=vite.config.js

Steps to reproduce

No response

System Info

System:
    window
Binaries:
      Node: 18.16.0
npmPackages:
      vite: ^5.3.2 => 5.3.2

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 1 month ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

hi-ogawa commented 2 weeks ago

Do you have any issue on your application after build? Otherwise, I think this is due to rollup's tree-shaking and having an empty chunk is only a minor inconvenience/limitation of rollup's manualChunks, so it's probably a rollup side issue at best.

I made a repro here https://github.com/hi-ogawa/reproductions/tree/main/vite-17694-rollup-manualChunks-empty where vite/rollup generates an empty chunk which is not "harmful":

// src/main.js
console.log("hello");

if (0) {
    console.log(import("lodash"));
}
$ npx vite build
vite v5.4.2 building for production...
✓ 7 modules transformed.
Generated an empty chunk: "lodash".
dist/vite/index.html             0.38 kB │ gzip: 0.26 kB
dist/vite/js/lodash-l0sNRNKZ.js  0.00 kB │ gzip: 0.02 kB
dist/vite/js/index-Bg9QWlBW.js   1.28 kB │ gzip: 0.53 kB
✓ built in 201ms

$ npx rollup -c rollup.config.js
./src/main.js → dist/rollup...
(!) Generated an empty chunk
"lodash"
created dist/rollup in 173ms

I'll close this issue for now. If you have a concrete issue in the application after build, please provide more details.