Skip to content

Nuxt.js Auto Import Error Fix

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Nuxt.js Auto Import Error Fix. We cover key concepts, practical examples, and best practices.

The Problem

nuxt 500 ReferenceError: useMyComposable is not defined

Nuxt auto-imports composables from the composables/ directory, but the function is not found because the file name does not match the expected pattern.

Wrong

composables/
└── helpers.js  # exports useMyComposable
<script setup>
const data = useMyComposable()
</script>

Output: ReferenceError: useMyComposable is not defined

Name the file with a use prefix:

composables/
└── useMyComposable.js
// composables/useMyComposable.js
export const useMyComposable = () => {
  return { data: 'hello' }
}
<script setup>
const { data } = useMyComposable()
</script>

Expected output: composable is auto-imported and the component renders with hello.

Prevention

  • Prefix composable file names with use (e.g., useAuth.js)
  • Export composables as named exports, not default exports
  • Restart the dev server after adding new composables

Common Mistakes with auto import

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world NUXTJS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What directories does Nuxt auto-import from?

Nuxt auto-imports from composables/, components/, utils/, middleware/, plugins/, and server/api/. Files in these directories are globally available without explicit imports.

Why is my composable not auto-imported?

The file name must start with use for composables. Check that the file is in composables/ and exports a function. Restart the dev server to refresh the auto-import registry.

Can I disable auto-import for specific files?

Yes. Use imports: { autoImport: false } in nuxt.config.ts to disable auto-import globally, or move the file outside the watched directories.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro