Vue · Lifecycle

VUE0004Clean up lifecycle resources

Checks that Vue lifecycle code includes the cleanup needed for predictable behavior.

Why it happens

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

Fix

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>

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 --rules vue/lifecycle/require-cleanup
Copyright © 2026