Repository navigation
Description
Vue version
3.5.18
Link to minimal reproduction
https://stackblitz.com/~/github.com/Ray-D-Song/vue-reactive-re-assignment
Steps to reproduce
pnpm buildWhat is expected?
The application was successfully built.
What is actually happening?
The app can run in dev mode, but the build will fail.
✗ Build failed in 279ms
error during build:
Build failed with 1 error:
[ILLEGAL_REASSIGNMENT] Error: Unexpected re-assignment of const variable `form`
╭─[ src/App.vue:20:68 ]
│
11 │ const form = reactive({
│ ──┬─
│ ╰─── `form` is declared here as const
│
20 │ "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((form) = $event))
│ ──┬─
│ ╰─── `form` is re-assigned here
────╯
System Info
System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Pro
Memory: 91.20 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.3.0 - ~/.nvm/versions/node/v24.3.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v24.3.0/bin/yarn
npm: 11.4.2 - ~/.nvm/versions/node/v24.3.0/bin/npm
pnpm: 10.12.4 - ~/.nvm/versions/node/v24.3.0/bin/pnpm
Browsers:
Chrome: 138.0.7204.168
Safari: 18.5
npmPackages:
vue: 3.5.18 => 3.5.18Any additional comments?
The core reason is that the Vue compiler generates code similar to the following:
const _sfc_main = {
__name: "App",
setup(__props) {
const form = reactive({
name: "ray-d-song",
age: 20
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("main", null, [
createVNode(_sfc_main$1, {
modelValue: form,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => form = $event) // the entire reactive variable will be reassigned
}, null, 8, ["modelValue"]),
createBaseVNode("h2", null, toDisplayString(form.name), 1),
createBaseVNode("h2", null, toDisplayString(form.age), 1)
]);
};
}
};Why only rolldown reports an error
Both rollup and rolldown will check for re-assignments to const variables, but rollup only reports an error for code where the declaration and re-assignment are in the same scope, while rolldown's checks are stricter.
For example, the following code will only throw an error in rolldown:
const foo = 'bar';
function test() {
foo = 'baz';
return foo
}This code will throw an error in both Rollup and Rolldown:
function test() {
const foo = 'bar';
foo = 'baz';
}The compilation result of Vue SFC is exactly the former.
Why the production code still works
The child component doesn't actually use the update method passed from the parent component to update, but instead generates update methods for the fields.
Activity
Ray-D-Song commentedon Jul 23, 2025
我创建了一个 PR 来修复:
#13694
linzhe141 commentedon Jul 23, 2025
I think it is similar to this issue
#11265
Ray-D-Song commentedon Jul 23, 2025
Yes, thank you for linking it!
I didn't find it because the problem was approached from a different angle.
These two perspectives lead to different repair methods, so I hope this issue can remain open.
LinusBorg commentedon Jul 23, 2025
duplicate