serversurfer
serversurfer2mo ago

Type instantiation is excessively deep and possibly infinite.ts for monorepo

This is happening to both internal and api (import { internal, api } from "./_generated/api") I've tried to simplify my schema, but to no avail. I am using the union validator, but on it's own variable.
7 Replies
erquhart
erquhart2mo ago
This is generally due to using ctx.runQuery/Mutation/Action somewhere and returning the value. Find the latest place you used one of the ctx.run* functions and you'll probably find your culprit. More here: https://docs.convex.dev/functions/actions#dealing-with-circular-type-inference
Actions | Convex Developer Hub
Call third-party services and external APIs from Convex
serversurfer
serversurferOP2mo ago
@erquhart could there be any other issue that causes this? I checked everywhere and made sure I'm not returning the value from ctx.run* Could it be an issue with my schema?
djbalin
djbalin2mo ago
How are you defining your schema? I ran into this using Table from convex-helpers in individual schema.ts files because I had circular references between these files
serversurfer
serversurferOP2mo ago
Oh I'm using defineTable and defineSchema Can't figure out this issue. I've used so many AI tokens already
djbalin
djbalin2mo ago
Try building your schema up from the ground and seeing where things break. Like, comment out everything, and then re-introduce stuff table-by-table or file by file etc
serversurfer
serversurferOP2mo ago
Was hoping to avoid this, but looks like it's going to have to be done For any one else who has this issue. I had a migrations.ts file that looks like this
import { Migrations } from "@convex-dev/migrations";
import { components } from "./_generated/api.js";
import { DataModel } from "./_generated/dataModel.js";

export const migrations = new Migrations<DataModel>(components.migrations);

// General purpose migration runner
export const run = migrations.runner();
import { Migrations } from "@convex-dev/migrations";
import { components } from "./_generated/api.js";
import { DataModel } from "./_generated/dataModel.js";

export const migrations = new Migrations<DataModel>(components.migrations);

// General purpose migration runner
export const run = migrations.runner();
After removing this file, the isse went away.
erquhart
erquhart2mo ago
I suspect that was a link in a chain and not the source of the problem, but yeah hard to see anything clearly with that type instantiation error. Did you have to drop the migrations component altogether or just alter your approach to using it?

Did you find this page helpful?