天翔
天翔16mo ago

Type instantiation is excessively deep and possibly infinite

G'day! For past two days i'm thinking how to solve an issue with queries and stuff like that. The issue is when I'm using useQuery. or anything other, i'm getting error with api with a message called Type instantiation is excessively deep and possibly infinite. Any ideas how to fix it?
12 Replies
ballingt
ballingt16mo ago
Sounds frustrating to have this problem for several days! This issue is usually caused by a syntax error in a Convex function or a Convex action that uses ctx.runMutation, ctx.runAction, or ctx.runQuery for type inference.
天翔
天翔OP16mo ago
okay, so maybe I can return to 1.2.1? Might help i guess
ballingt
ballingt16mo ago
No, changing the version of Convex shouldn't help. This is an issue with your queries, mutations, or actions in your convex/ folder.
天翔
天翔OP16mo ago
well, my functions are not problem. For example:
export const find = query({
args: {
userId: v.string(),
},
handler: async (ctx, args) => {
return await ctx.db.query("profile").filter((q) => q.eq(q.field("userId"), args.userId)).unique();
}
})
export const find = query({
args: {
userId: v.string(),
},
handler: async (ctx, args) => {
return await ctx.db.query("profile").filter((q) => q.eq(q.field("userId"), args.userId)).unique();
}
})
which does not have any problems
ballingt
ballingt16mo ago
If you open up convex/generated/api.d.ts are any of the imports broken? (underlined in red)
天翔
天翔OP16mo ago
no, i don't see any
ballingt
ballingt16mo ago
Unfortunately an error in one of these functions can cause this problem in all of them — so you need to check them all could you share your code? feel free to DM
Michal Srb
Michal Srb16mo ago
With a lot (a lot) of code this might not be caused by errors. To get around it type annotate the return type of your functions (especial actions using runQuery/runMutation). But wrong imports/empty files inside convex are more likely.
Indy
Indy16mo ago
Yea this happened to me recently. Looking through my notes I had a bad import statement in one of my convex query files.
ballingt
ballingt16mo ago
We looked at this together, turns out it was some empty files in convex/ empty files aren't valid modules so TypeScript was sad. We'll look at improving the error message here.
天翔
天翔OP16mo ago
I was thinking maybe there's some rules that can be disabled for a compiler? Like some eslint errors
Rispy
Rispy13mo ago
I ran into same issue and don't have idea how to fix it no empty files in convex dir

Did you find this page helpful?