Using Convex query gives Cannot find module '@/convex/_generated/api'
I am working on a Next.js convex project and I am having some trouble with running a query. The project has these dirs app, convex and models. app contains the next js app, and the models has some ts code to interact with ai models
in the models dir I am trying to run this query which runs against this table
and here is the query code
When I try and call the query from models I get this error and when I try and run it from a prompt.ts file in the convex dir i get Any help would be really appriciated, thanks
5 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Your use of the
useQuery
hook doesn't look correct. It doesn't return a promise, so await
isn't necessary.
Have you run npx convex dev
? This not only connects you to your Convex account, but it also refreshes the generated code during development, and some of the error messages you list make it feel like something didn't get generated.You might try an example app first, e.g. checking out https://github.com/get-convex/convex-demos and cd-ing to the typescript directory, then
npm install
and npm run dev
There are a few pieces that dont' sound hooked up here, it might help to see them allworking together
What are models, is this server code?
useQuery
is specifically for React componentsYou should also see Typescript errors in your files if it can't find the resources you're trying to use.
Im also now trying to use it in a mutation and im getting this error
this is the mutation
and the schema
I resolved this, by reafactoring the logic and removing the promptId from the prompt table