#Strage Error query2

26 messages · Page 1 of 1 (latest)

marble cargo
#

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)

shy trellis
#

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?

marble cargo
#

nope i added it to two files and named it differently and just the one is not working

shy trellis
#

Can you share your custom query and the other function that is working

marble cargo
#

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;
},
});

mossy lynx
#

It doesn't work to create a query called "query" if you're also using the query() wrapper in the same file

marble cargo
shy trellis
#

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)?

marble cargo
#

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

left fox
#

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)

marble cargo
#

ill try it, actionMessages.js is not my code because i'm all .ts files

left fox
#

Yep that's bundled code (which is .js and .js.map files)

mossy lynx
#

could you share that file, permissions.ts? It sounds like query might be bound to something else there

marble cargo
#

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

Convex, Clerk, Next.js, Convex Ents. Contribute to xixixao/saas-starter development by creating an account on GitHub.

marble cargo
#

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.

marble cargo
marble cargo
#

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

shy trellis
#

@marble cargo if you can push up a minimal repro and link it here I'll get into it first thing in the morning.

marble cargo
#

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.

marble cargo
#

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 @rose thicket 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

Convex, Clerk, Next.js, Convex Ents. Contribute to amp127/saas-starter development by creating an account on GitHub.