edinstanceE
Convex Community2y ago
9 replies
edinstance

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
  const activePrompt = await useQuery(api.prompts.getActivePrompt);
which runs against this table
prompts: defineTable({
    promptId: v.id("prompts"),
    prompt: v.string(),
    isActive: v.boolean(),
  }).index("by_active", ["isActive"]),
});


and here is the query code
import { query } from "./_generated/server";


export const getActivePrompt = query({
    args: {},
    handler: async (ctx) => {
      return await ctx.db.query("prompts").withIndex("by_active").first();
    },
  });


When I try and call the query from models I get this error
models/index.ts:6:21 - error TS2307: Cannot find module '@/convex/_generated/api' or its corresponding type declarations.

6 import { api } from "@/convex/_generated/api";
                      ~~~~~~~~~~~~~~~~~~~~~~~~~
and when I try and run it from a prompt.ts file in the convex dir i get
Property 'prompts' does not exist on type '{ auth: { signIn
Any help would be really appriciated, thanks
Was this page helpful?