useAsyncData/useFetch must be called in setup (key/context) Vue Origin: On your device OSI layer 7 · Application Last updated 5 Nov 2026

Nuxt: [nuxt] [useAsyncData] key must be a string / useFetch only works inside setup, plugins or middleware

useFetch/useAsyncData were used in an event handler, after an await, or without a key where one is required.

Exact message you may see [nuxt] [useAsyncData] key must be a stringuseFetch is a composable and should only be called in setup[nuxt] A composable that requires access to the Nuxt instance was called outside of a pluginuseAsyncData is called outside setupNuxt useFetch called inside event handler
Seen on: Vue Node.js

Meaning

Call them synchronously during setup. For user-triggered requests use $fetch (no SSR caching) or refresh()/execute() on the returned object. Provide a unique key to useAsyncData when not auto-generated (e.g. in wrapper composables).

Common causes

  • Called in click handler/watch callback
  • After an await in setup (context lost)
  • Missing/duplicate key in composables
  • Used inside plain utility functions
  • Inside a plugin without runWithContext

⚡ Quick fix

  1. Use $fetch for event-driven calls
  2. Call useFetch at the top level of setup and refresh() later
  3. Add unique keys: useAsyncData("posts", ...)

Detailed fix by platform

Nuxt

  1. const { data, refresh } = await useFetch("/api/posts"); // refresh() in handlers

How to diagnose

  1. Call site — Setup?
  2. Trigger — Event?
  3. Key — Unique?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

[Vue warn]: onMounted is called when there is no active component instance — Vue: [Vue warn]: onMounted is called when there is no active component instance to be associated with (Vue)[Vue warn]: onMounted…Nuxt 404: Page not found (route/file naming) — Nuxt: 404 Page not found: /blog/my-post / [Vue Router warn]: No match found for location with path (Vue)Nuxt 404: Page not fo…Nuxt: Failed to fetch dynamically imported module (after deploy) — Nuxt: [nuxt] error caught during app initialization TypeError: Failed to fetch dynamically imported module / Loading chunk failed (Vue)Nuxt: Failed to fetch…Nuxt: Hydration completed but contained mismatches — Nuxt: [Vue warn]: Hydration completed but contains mismatches. (Vue)Nuxt: Hydration compl…Nuxt: window/document/localStorage is not defined (SSR) — Nuxt: ReferenceError: window is not defined / 500 Internal Server Error during SSR (Vue)Nuxt: window/document…Nuxt/Vite: Failed to resolve import "~/..." or "@/..." — Nuxt: [vite] Internal server error: Failed to resolve import "~/components/Foo.vue" from "pages/index.vue". Does the file exist? (Vue)Nuxt/Vite: Failed to …useAsyncD…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.