Vue · State

VUE0048Write shared state through its module's actions

Finds shared state that a module exports with Vue's `reactive()` or `ref()` and changes directly in a public function or state method, but that two or more other files still write directly. Doctor detects assignments (including destructuring), `++`/`--`, `delete`, builtin `Object.assign`, and mutating methods on arrays, Maps, or Sets identified from the initializer. It also detects these writes and `v-model` in `<script setup>` templates. It follows static imports and named, default, namespace, and single-star forwarding, but does not guess which export wins in a barrel with multiple star exports. It reports at the declaration and links each detected external write. Named reset functions that only restore the initial values do not establish an action API. Reads, writes inside the owning module, writes through an alias such as `const s = store`, Pinia stores, props, and `defineModel` are not reported. Strict Preset only.

Why it happens

Vue's state management guide shows a module that exports reactive state and recommends defining the actions that mutate it in the same module, so every change can be found and traced from one place. When the module already provides those actions and components still write the state directly, the changes are scattered across files and skip whatever the actions enforce, such as validation or derived bookkeeping.

Fix

Call the module's existing actions from the components, or add an action for a change the module does not cover yet. Keep the state in the module; do not copy it into each component or move ownership into one component.

Example

Change shared state through the store's actions

Before

<!-- store.ts -->
<script lang="ts">
export const store = reactive({ count: 0 })
export function increment() {
  store.count++
}
</script>

<!-- Counter.vue and ResetButton.vue -->
<script setup lang="ts">
import { store } from './store'
</script>

<template>
  <button @click="store.count++">{{ store.count }}</button>
  <button @click="store.count = 0">Reset</button>
</template>

After

<!-- store.ts -->
<script lang="ts">
export const store = reactive({ count: 0 })
export function increment() {
  store.count++
}
export function reset() {
  store.count = 0
}
</script>

<!-- Counter.vue and ResetButton.vue -->
<script setup lang="ts">
import { increment, reset, store } from './store'
</script>

<template>
  <button @click="increment()">{{ store.count }}</button>
  <button @click="reset()">Reset</button>
</template>

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework vue --extends auto,vue/strict --rules vue/state/no-external-shared-state-mutation
Copyright © 2026