Nuxt Content queryCollection not found
const { data: prizes } = await useAsyncData('prizes', () => {
return queryCollection('prizes').order('date', 'ASC').all()
})
Cannot find name 'queryCollection'.ts-plugin(2304)
2 Replies
Hi @Uchuu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error "Cannot find name 'queryCollection'" usually means that the
Make sure you have
The
If you are using a TypeScript file, ensure that your IDE recognizes Nuxt's auto-imports. Sometimes, restarting your IDE or running
Make sure you have defined the
In your Vue files, you can use
queryCollection
function is not available in your current scope. According to the Nuxt Content documentation, queryCollection
is auto-imported when using Nuxt Content v3, so you should not need to import it manually in most cases. However, this auto-import only works if Nuxt Content is properly installed and configured in your project.
Here are some steps to resolve the issue:
1. Ensure Nuxt Content is installed and enabledMake sure you have
@nuxt/content
installed and added to your nuxt.config.ts
modules.
2. Check your Nuxt Content versionThe
queryCollection
API is available in Nuxt Content v3 and later. If you are using an older version, you may need to upgrade and migrate from queryContent
to queryCollection
as described in the migration guide see migration changes.
3. Auto-importsIf you are using a TypeScript file, ensure that your IDE recognizes Nuxt's auto-imports. Sometimes, restarting your IDE or running
nuxi prepare
can help update type definitions.
4. Define your collectionMake sure you have defined the
prizes
collection in your content.config.ts
file. For example:
Defining Collections
5. Usage in Vue filesIn your Vue files, you can use
queryCollection
directly as shown:
Query Utils: queryCollection
If you have followed all these steps and still see the error, double-check that your Nuxt Content module is up to date and that your IDE is not caching old type definitions.
If you are using the server API (e.g., in server/api/
), you need to pass the event
as the first argument to queryCollection
:
Server Usage
If the problem persists after these checks, please provide more details about your project setup and Nuxt Content version.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1035470271441805353> Kapa.ai is still learning and improving, please let me know how I did by reacting below.