ampp
ampp•11mo ago

Strage Error query2

export const getPermissionList = query({ args: {}, async handler(ctx) { const permissions = await ctx.table("permissions").map((permission) => ({ _id: permission._id, name: permission.name, })); return permissions; }, }); is giving this error: Error fetching POST https://convex-url-240.convex.cloud/api/push_config 400 Bad Request: InvalidModules: Hit an error while pushing: Loading the pushed modules encountered the following error: Failed to analyze actionMessages.js: Uncaught TypeError: query2 is not a function at <anonymous> (../../convex/permissions.ts:153:9) Notes: query is using my query in functions.ts as with convex-ents examples im using the same function elsewhere with a different table name/function name and in a different its working just fine. (as we have 3 permission tables)
19 Replies
erquhart
erquhart•11mo ago
Does query2 not appear in your source anywhere? If not this sounds like some kind of bundler/packaging issue I would also check whether this was introduced by a specific change in your code, eg., does a previous commit work?
ampp
amppOP•11mo ago
nope i added it to two files and named it differently and just the one is not working
erquhart
erquhart•11mo ago
Can you share your custom query and the other function that is working
ampp
amppOP•11mo ago
export const query = customQuery( baseQuery, customCtx(async (baseCtx) => { return await queryCtx(baseCtx); }) ); async function queryCtx(baseCtx: BaseQueryCtx) { const ctx = { ...baseCtx, db: undefined, table: entsTableFactory(baseCtx, entDefinitions), }; const identity = await ctx.auth.getUserIdentity(); const viewer = identity === null ? null : await ctx .table("users") .get("tokenIdentifier", identity.tokenIdentifier); const viewerX = () => { if (viewer === null) { throw new Error("Expected authenticated viewer"); } return viewer; }; return { ...ctx, viewer, viewerX }; } export const getMemberPermissionList = query({ args: {}, async handler(ctx) { const permissions = await ctx.table("memberPermissions").map((permission) => ({ _id: permission._id, name: permission.name, })); return permissions; }, });
ballingt
ballingt•11mo ago
It doesn't work to create a query called "query" if you're also using the query() wrapper in the same file
ampp
amppOP•11mo ago
GitHub
saas-starter/convex/functions.ts at main · xixixao/saas-starter
Convex, Clerk, Next.js, Convex Ents. Contribute to xixixao/saas-starter development by creating an account on GitHub.
erquhart
erquhart•11mo ago
It's hard to troubleshoot this without context. Is your functions.ts pretty sizeable or would you be able to share the whole thing (temporarily)?
ampp
amppOP•11mo ago
im fairly sure functions.ts is line for line a exact match to the saas-starter example i use query all over the place, its just this one , and its baffling
sshader
sshader•11mo ago
As an avenue for debugging, you could try npx convex dev --once --debug-bundle-path /tmp/wherever (you'll want to be on the most recent version of convex) which will spit out the bundle in the specified directory without actually pushing it (so you could look at actionMessages.js and see what query2 is)
ampp
amppOP•11mo ago
ill try it, actionMessages.js is not my code because i'm all .ts files
sshader
sshader•11mo ago
Yep that's bundled code (which is .js and .js.map files)
ballingt
ballingt•11mo ago
could you share that file, permissions.ts? It sounds like query might be bound to something else there
ampp
amppOP•11mo ago
I took out most of the functions as they aren't actually implemented yet, it still errors, its very similar to the https://github.com/xixixao/saas-starter/blob/main/convex/permissions.ts import { Infer, v } from "convex/values"; import { MutationCtx, QueryCtx } from "../../types"; import { Role } from "../members/permissions"; import { query } from "../../functions"; export const vPermission = v.union( v.literal("Can View"); + 20 more ); export type Permission = Infer<typeof vPermission>; export async function getPermission(ctx: QueryCtx, name: permission) { return (await ctx.table("permissions").getX("name", name))._id; } export async function getRole(ctx: QueryCtx, name: Role) { return await ctx.table("roleDefinitions").getX("name", name); } export const getPermissionList = query({ args: {}, async handler(ctx) { const permissions = await ctx.table("permissions").map((permission) => ({ _id: permission._id, name: permission.name, })); return permissions; }, });
GitHub
saas-starter/convex/permissions.ts at main · xixixao/saas-starter
Convex, Clerk, Next.js, Convex Ents. Contribute to xixixao/saas-starter development by creating an account on GitHub.
ampp
amppOP•11mo ago
i suppose its possible its conflicting with my other permissions.ts file in a different folder with mostly the same functionality but every function is named differently. as you can see i reference Role in the other file ../member/permissions.ts . That file has the working getPermissionList, but named getMemberPermissionList. Both files use Roles to generate their specifically named roleDefinitions files. However this is a far stretch because the query doesnt touch the roleDefintion table. Ok, updated my convex, ents, helpers: I did not realize that actionMessages is one of our tables of like 60 something. Its mostly stubbed for later use. the export actionmessages.js does not have query2 in it. It has a single create = mutation function copied from my other convex files that has no relation to permissions in any way. So that is Weird... I'm lost, i generated a bundle path with and without a the offending line of code and i cant see a difference in generated output except the missing function. I also don't understand why some of the bundle function files show lots of functions and some are just imports. however if i delete everything in my actionMessages.ts the error changes: Error fetching POST https://myurl.convex.cloud/api/push_config 400 Bad Request: InvalidModules: Hit an error while pushing: Loading the pushed modules encountered the following error: Failed to analyze functions.js: Uncaught TypeError: query2 is not a function at <anonymous> (../../convex/perm2/permissions.ts:153:9) tried renaming the file to just see if it was some sort of name conflict
erquhart
erquhart•11mo ago
@ampp if you can push up a minimal repro and link it here I'll get into it first thing in the morning.
ampp
amppOP•11mo ago
not sure i have the time to do that. But i did just confirm the error is interconnected, if i comment out the differently named function(but functionally the same outside a table name difference) in the ../member/permissions.ts file npx convex dev likes it.. so it has to be some sort of "conflict".. finding a work around is faster. its not a show stopping issue yet.
ampp
amppOP•11mo ago
I was thinking I can't replicate it on saas-starter template fast, because I cant exactly copy over all our code surrounding this. but i managed to replicate it 🙂 and it rules out my mono-repo env etc. i moved the permission files into folders like i have. https://github.com/amp127/saas-starter @Michal Srb im using your code to showcase this. Anyway in the schema as soon as you use vPermission2 instead of vPermission on the 2nd permission table it breaks one of the list functions isnt commented out. and shows the same error referencing query2.
GitHub
GitHub - amp127/saas-starter: Convex, Clerk, Next.js, Convex Ents
Convex, Clerk, Next.js, Convex Ents. Contribute to amp127/saas-starter development by creating an account on GitHub.
ampp
amppOP•11mo ago
No description
Michal Srb
Michal Srb•11mo ago
Great job @ampp, this does repro. For now the workaround is to avoid using the custom query constructor in files that are used by the schema.ts file. In this repo that's moving the getMemberPermissionList query that is in the convex/users/teams/members/permissions.ts file. This looks like a bundling issue.

Did you find this page helpful?