Diogo Rocha
Diogo Rocha•2w ago

Type instantiation is excessively deep and possibly infinite.

I honestly can't understand the reason for this error... can you help me? It works but only the build doesn't work.
No description
39 Replies
Sara
Sara•2w ago
intresting, mind sharing both your root tsconfig and the one in the /convex folder?
erquhart
erquhart•2w ago
Also, this can be caused by an unrelated ctx.runQuery/runMutation/runAction in a different file. If a function uses any of these and returns the result or any part of the result without an explicit type, you can get this error in seemingly random files. (Not actually random, but it can seem that way). More here: https://docs.convex.dev/functions/actions#dealing-with-circular-type-inference
Diogo Rocha
Diogo RochaOP•2w ago
convex\tsconfig.json:
{
/* This TypeScript project config describes the environment that
* Convex functions run in and is used to typecheck them.
* You can modify it, but some settings required to use Convex.
*/
"compilerOptions": {
/* These settings are not required by Convex and can be modified. */
"allowJs": true,
"strict": true,
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,

/* These compiler options are required by Convex */
"target": "ESNext",
"lib": ["ES2021", "dom"],
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"isolatedModules": true,
"noEmit": true
},
"include": ["./**/*"],
"exclude": ["./_generated"]
}
{
/* This TypeScript project config describes the environment that
* Convex functions run in and is used to typecheck them.
* You can modify it, but some settings required to use Convex.
*/
"compilerOptions": {
/* These settings are not required by Convex and can be modified. */
"allowJs": true,
"strict": true,
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,

/* These compiler options are required by Convex */
"target": "ESNext",
"lib": ["ES2021", "dom"],
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"isolatedModules": true,
"noEmit": true
},
"include": ["./**/*"],
"exclude": ["./_generated"]
}
tsconfig.json:
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./src/*"
]
},
"target": "ES2017"
},
"include": [
"**/*.ts",
"**/*.tsx",
"next-env.d.ts",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./src/*"
]
},
"target": "ES2017"
},
"include": [
"**/*.ts",
"**/*.tsx",
"next-env.d.ts",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
Sara
Sara•2w ago
its the tsconfig try this, does it casue the same issues, I'm talking about the one in the root folder directory:
{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"next.config.js"
],
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"next.config.js"
],
"exclude": ["node_modules"]
}
this is a less strict one, and doesn't specify target, which might be the case here
Diogo Rocha
Diogo RochaOP•2w ago
This change will force me to change the entire project
No description
Diogo Rocha
Diogo RochaOP•2w ago
But the same error still appears
Diogo Rocha
Diogo RochaOP•2w ago
No description
Sara
Sara•2w ago
keep the src route then and remove the target only?
Diogo Rocha
Diogo RochaOP•2w ago
{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"next.config.js"
],
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"next.config.js"
],
"exclude": ["node_modules"]
}
But the error remains :/
Sara
Sara•2w ago
I don't think this is the problem anymore
Diogo Rocha
Diogo RochaOP•2w ago
No description
Sara
Sara•2w ago
oh.. do you have the convex folder as features?
Diogo Rocha
Diogo RochaOP•2w ago
https://docs.convex.dev/functions/actions#dealing-with-circular-type-inference Maybe that's the problem, right? From what I've been reading
Actions | Convex Developer Hub
Call third-party services and external APIs from Convex
Diogo Rocha
Diogo RochaOP•2w ago
This doesn't happen on all platforms, the project is huge, it only appears on some APIs, and sometimes it's random..
Sara
Sara•2w ago
it mght be.. which is still weird can you hover over api and take a screenshot/copy paste the type?
Diogo Rocha
Diogo RochaOP•2w ago
It's strange because it doesn't happen in all files, and as I said, there are no errors, everything works perfectly.
Sara
Sara•2w ago
yes!
Diogo Rocha
Diogo RochaOP•2w ago
convex_generated\api.d.ts - this?
Sara
Sara•2w ago
that should do!
Diogo Rocha
Diogo RochaOP•2w ago
Sara
Sara•2w ago
for that particular query, are you using ctx.runQuery, ctx.runMutation etc?
Diogo Rocha
Diogo RochaOP•2w ago
check:
/**
* 📋 Get all linked accounts for the current user
*/
export const getLinkedAccounts = query({
args: {},
handler: async (ctx) => {
const userId = await auth.getUserId(ctx);
if (!userId) {
throw new Error("User not authenticated");
}

// Fetch all linked accounts
const accounts = await ctx.db
.query("authAccounts")
.withIndex("userIdAndProvider", (q) => q.eq("userId", userId))
.collect();

// Filter out Magic Link accounts - they should not appear as linked accounts
const filteredAccounts = accounts.filter(account =>
account.provider !== "resend-magic-link"
);

// Format data for frontend
return filteredAccounts.map(account => ({
id: account._id,
provider: account.provider,
providerAccountId: account.providerAccountId,
createdAt: account._creationTime,
}));
},
});
/**
* 📋 Get all linked accounts for the current user
*/
export const getLinkedAccounts = query({
args: {},
handler: async (ctx) => {
const userId = await auth.getUserId(ctx);
if (!userId) {
throw new Error("User not authenticated");
}

// Fetch all linked accounts
const accounts = await ctx.db
.query("authAccounts")
.withIndex("userIdAndProvider", (q) => q.eq("userId", userId))
.collect();

// Filter out Magic Link accounts - they should not appear as linked accounts
const filteredAccounts = accounts.filter(account =>
account.provider !== "resend-magic-link"
);

// Format data for frontend
return filteredAccounts.map(account => ({
id: account._id,
provider: account.provider,
providerAccountId: account.providerAccountId,
createdAt: account._creationTime,
}));
},
});
erquhart
erquhart•2w ago
I would grep the project for ctx.run to see where it's being used Doesn't have to be in the same function I've had times where my entire project wouldn't generate at all
Sara
Sara•2w ago
the only fix occurring to google is to cast type, try passing a type in the query itself, say
export const getLinkedAccounts = query({
args: {},
returns:{ //** The expected type here using v validator *//},
handler: async (ctx) => {
const userId = await auth.getUserId(ctx);
if (!userId) {
throw new Error("User not authenticated");
}

// Fetch all linked accounts
const accounts = await ctx.db
.query("authAccounts")
.withIndex("userIdAndProvider", (q) => q.eq("userId", userId))
.collect();

// Filter out Magic Link accounts - they should not appear as linked accounts
const filteredAccounts = accounts.filter(account =>
account.provider !== "resend-magic-link"
);

// Format data for frontend
return filteredAccounts.map(account => ({
id: account._id,
provider: account.provider,
providerAccountId: account.providerAccountId,
createdAt: account._creationTime,
}));
},
});
export const getLinkedAccounts = query({
args: {},
returns:{ //** The expected type here using v validator *//},
handler: async (ctx) => {
const userId = await auth.getUserId(ctx);
if (!userId) {
throw new Error("User not authenticated");
}

// Fetch all linked accounts
const accounts = await ctx.db
.query("authAccounts")
.withIndex("userIdAndProvider", (q) => q.eq("userId", userId))
.collect();

// Filter out Magic Link accounts - they should not appear as linked accounts
const filteredAccounts = accounts.filter(account =>
account.provider !== "resend-magic-link"
);

// Format data for frontend
return filteredAccounts.map(account => ({
id: account._id,
provider: account.provider,
providerAccountId: account.providerAccountId,
createdAt: account._creationTime,
}));
},
});
if that didn't work, I don't know what could possibly be the issue tbh
Diogo Rocha
Diogo RochaOP•2w ago
But it exists and works perfectly
No description
erquhart
erquhart•2w ago
But it's not deploying because of the error right Or did you deploy with typechecking off
Sara
Sara•2w ago
// @ts-ignore :classic:
Diogo Rocha
Diogo RochaOP•2w ago
This is what I use but I would like to understand the reason sincerely 😂
erquhart
erquhart•2w ago
Ah yeah get rid of those Your OP was about a different function, is there a reason the focus is on the linked accounts function now?
Sara
Sara•2w ago
I asked him, because I wondered if it was because of an internal function somewhere that might be causign it
erquhart
erquhart•2w ago
ah because he posted the image of the error in that function I see it now
Diogo Rocha
Diogo RochaOP•2w ago
No, but like I said, this "shitty" error keeps popping up in various files sometimes and it annoys me because everything is working 😂
erquhart
erquhart•2w ago
You have to search for instances of ctx.run* to chase this down
Diogo Rocha
Diogo RochaOP•2w ago
I'm new to Convex and I'm migrating my project to Convex because I confess I fell in love with it.
erquhart
erquhart•2w ago
It's the only way.
Diogo Rocha
Diogo RochaOP•2w ago
Okay, I'll look into this properly Thank you very much for your help both of you I had a serious problem with self-hosted I posted it a few weeks ago but they didn't help me. Because when I migrate the main project to convex, I will have more than 500 users using this simultaneously during the day
Justin
Justin•3d ago
Finding this cause I had the same error and thought my findings might help others. After setting return types on everything the issue still wasn't resolved. I eventually started removing pieces one by one and found this was the culprit:
args: {
metadata: v.optional(v.record(v.string(), v.any())),
},
args: {
metadata: v.optional(v.record(v.string(), v.any())),
},
TypeScript didn't like the v.any() as the second parameter to v.record. However, there was no warning/error associated with this line. I just discovered that changing the type or removing this arg completely resolved the infinite depth error. LLMs really like any ... 😒
erquhart
erquhart•3d ago
Interesting, using v.any() should work okay for records. There were no other compounding factors?

Did you find this page helpful?