#Error when running 'npx convex dev' command

1 messages · Page 1 of 1 (latest)

lilac pagoda
#

I am hosting my own convex backend. When trying to run the npx convex dev command with the schema.ts file being there I get the following error message in the terminal and I get two lines in the terminal :
⠏ Preparing Convex functions... ⠹ Checking for index or schema changes....

If I delete the schema file and then run the command then it does not error out but when I add back the schema.ts file I get the following error:
✔ Added table indexes: [+] todos.by_completed ["completed","_creationTime"] Unexpected Error: TypeError: Cannot read properties of undefined (reading 'length')
and the function stops.

#

Below are the content of the files:

schema.ts
`import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";

// Data model for a single-user Todo app
export default defineSchema({
todos: defineTable({
text: v.string(),
completed: v.boolean(),
}).index("by_completed", ["completed"]), // for clearing completed
});`

todo.ts
`import { mutation, query } from "./_generated/server";
import { v } from "convex/values";

export const list = query({
args: {},
handler: async (ctx) => {
const todos = await ctx.db.query("todos").order("asc").collect();
return todos;
},
});

export const add = mutation({
args: { text: v.string() },
handler: async (ctx, args) => {
const text = args.text.trim();
if (text.length === 0) {
throw new Error("Text is required");
}
const id = await ctx.db.insert("todos", {
text,
completed: false,
});
return id;
},
});

export const toggle = mutation({
args: { id: v.id("todos"), completed: v.boolean() },
handler: async (ctx, args) => {
await ctx.db.patch(args.id, { completed: args.completed });
},
});

export const clearCompleted = mutation({
args: {},
handler: async (ctx) => {
const completed = await ctx.db
.query("todos")
// .withIndex("by_completed", (q) => q.eq("completed", true))
.collect();
for (const todo of completed) {
await ctx.db.delete(todo._id);
}
return completed;
},
});`

mighty topaz
#

Thanks for starting the thread. The basics of your files look fine from what I can see. That said, I'm not sure that I'll be able to help much more. You mentioned in your post here that you're trying to self-host. I've not gone down that path, so I'm not sure if some config with the self-hosting setup could be to blame, and I wouldn't know where to start. I see that you also posted for help in the #self-hosted channel, so I'm crossing my fingers that someone with self-hosting experience can help you figure things out. Sorry that I can't do more.

lilac pagoda
mighty topaz