Nuxt · NUXT0077
Keep setup-bound functions out of utils/
Finds functions in Nuxt utils/ that need a component setup context and belong in composables/.
nuxt/structure/no-composable-in-utilssrc/rule-packs/nuxt/rules/nuxt/composable-placement.ts Upstream docs Run this rule
pnpm nuxt doctor --rules nuxt/structure/no-composable-in-utils
Why it matters
Nuxt auto-imports both composables/ and utils/, so the directory is how readers know whether a function must run during setup. A utils/ function that calls lifecycle hooks, inject(), provide(), or other composables breaks when it is called from an event handler, timer, or plugin the way plain utilities are.
Recommended fix
Move the function to composables/ and name it with the use prefix. Functions that only read Nuxt app context, such as useNuxtApp(), useRuntimeConfig(), useRouter(), or useState(), can stay in utils/, like Nuxt's own navigateTo().
Useful links
Example
Move setup-bound tracking into a composable
Before
// app/utils/track.ts
export function trackPageView() {
const route = useRoute()
onMounted(() => analytics.page(route.fullPath))
}
After
// app/composables/usePageTracking.ts
export function usePageTracking() {
const route = useRoute()
onMounted(() => analytics.page(route.fullPath))
}