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
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?nope i added it to two files and named it differently and just the one is not working
Can you share your custom query and the other function that is working
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;
},
});
"query"
if you're also using the query()
wrapper in the same fileits a seperate file, im setup the same as https://github.com/xixixao/saas-starter/blob/main/convex/functions.ts
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.
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)?
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
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)ill try it, actionMessages.js is not my code because i'm all .ts files
Yep that's bundled code (which is
.js
and .js.map
files)could you share that file, permissions.ts? It sounds like query might be bound to something else there
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.
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
@ampp if you can push up a minimal repro and link it here I'll get into it first thing in the morning.
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.
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.
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.