-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Labels
p2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)
Description
Describe the bug
When nameCache is provided, it gets cloned for each worker thread, resulting in isolated caches that are not synchronized back to the main thread.
This inconsistency can cause key–value mismatches for the same type of object in different chunks, making the nameCache
ineffective and leading to incorrect minification results.
Reproduction
https://github.com/AntaresQAQ/vite-terser-bug-repro
Steps to reproduce
Vite Config
import { defineConfig } from "vite";
const nameCache = {};
// https://vite.dev/config/
export default defineConfig({
plugins: [
{
name: "terser-mangle-props-cache",
closeBundle() {
console.log("Name cache:", nameCache);
},
},
],
build: {
minify: "terser",
terserOptions: {
compress: false,
mangle: {
properties: true,
},
nameCache,
},
},
});
Codes
obj1.ts
import type { IDemoObj } from "./types";
const obj: IDemoObj = {
baz: "baz",
foo: "foo",
qux: "qux",
bar: "bar",
};
export default obj;
src/obj2.ts
import type { IDemoObj } from "./types";
const obj: IDemoObj = {
foo: "foo",
bar: "bar",
baz: "baz",
qux: "qux",
};
export default obj;
Built files
- chunk
obj1-Ds7_RE47.js
const a={o:"baz",t:"foo",u:"qux",q:"bar"};export{a as default};

- chunk
obj2-DqD_p4d0.js
const a={o:"foo",t:"bar",u:"baz",q:"qux"};export{a as default};

Vite outputs
yarn run v1.22.22
$ tsc -b && vite build
vite v7.1.5 building for production...
✓ 6 modules transformed.
dist/index.html 0.39 kB │ gzip: 0.27 kB
dist/assets/obj1-Ds7_RE47.js 0.06 kB │ gzip: 0.08 kB
dist/assets/obj2-DqD_p4d0.js 0.06 kB │ gzip: 0.08 kB
dist/assets/index-BJnHZlGe.js 2.21 kB │ gzip: 1.03 kB
✓ built in 171ms
Name cache: {}
✨ Done in 0.84s.
Expected Result
- the
obj1
is the same asobj2
. - the
nameCache
is not empty.
System Info
System:
OS: macOS 15.6.1
CPU: (10) arm64 Apple M2 Pro
Memory: 263.14 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.16.0 - ~/.nvm/versions/node/v22.16.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.16.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v22.16.0/bin/npm
Browsers:
Chrome: 140.0.7339.133
Safari: 18.6
npmPackages:
vite: ^7.1.2 => 7.1.5
Used Package Manager
yarn
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
p2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)