Vue · VUE0004

Clean up lifecycle resources

Checks that Vue lifecycle code includes the cleanup needed for predictable behavior.
VUE0004vite-doctor/vuelifecyclewarnSuggestion

Run this rule

pnpm vite-doctor . --framework vue --rules vue/lifecycle/require-cleanup

Why it matters

Effects that outlive their component create leaks and stale updates. Register cleanup where Vue or VueUse can dispose it automatically.

Add cleanup where Vue expects it, close to the code that depends on it.

Example

Clean up lifecycle side effects

Before

<script setup lang="ts">
onMounted(() => {
  window.addEventListener('resize', onResize)
})
</script>

After

<script setup lang="ts">
onMounted(() => {
  window.addEventListener('resize', onResize)
})
onBeforeUnmount(() => {
  window.removeEventListener('resize', onResize)
})
</script>
Copyright © 2026