serversurfer
serversurfer5mo 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.
11 Replies
erquhart
erquhart5mo 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
serversurferOP5mo 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
djbalin5mo 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
serversurferOP5mo ago
Oh I'm using defineTable and defineSchema Can't figure out this issue. I've used so many AI tokens already
djbalin
djbalin5mo 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
serversurferOP4mo 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
erquhart4mo 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?
yh
yh3mo ago
the culprit line is export const run = migrations.runner(); when it is removed the error is gone. cant get the migrations component to work :/
Demian
Demian6d ago
Was this issue solved? I get the same error because of the same line in #Type instantiation is excessively deep and possibly infinite Can this be a circular dependency?: 1. It infers types from DataModel 2. DataModel is generated from your schema 3. The schema/types may reference API types 4. The API types include the migrations component Okay, moving migration from separate file to migrations.ts with everything else seems to do the trick @erquhart , if this is indeed the issue would it make sense to update the migration docs?
Loco
Loco2d ago
@Demian how did you end up solving ?
Demian
Demian2d ago
As I said, I just moved everything to one file let the convex dev run once and the problem is solved If it would help I can send a code example when I'm back near laptop

Did you find this page helpful?