`convex-test` could not find the "_generated" directory
Just installed
convex-test
and wrote a very simple test at the root of my /convex
folder. Running it produces an error:
My _generated
directory is present and my convex functions are all in /convex
at the root of my project. Not sure what might be the issue.
12 Replies
how does your package.json look like?
@Eva facing the same issue...how did you fix it?
I had the same issue and fixed it with this
In nextjs i get this error:
js Property 'glob' does not exist on type 'ImportMeta'.ts(2339)
nextjs shouldn't even be loading the test file, are you exporting anything from the test file that might be used in your nextjs code?
No I'm only doing imports in my test files

re:
Could not find the "_generated" directory
-- I think something about pnpm sometimes does not play nicely with convexTest
automatically finding your convex functions.
The workaround is what morvud described of passing in a import.meta.glob
(and I'll update the docs + error message to recommend this for pnpm).
To get import.meta.glob
to typecheck, I believe you want to add /// <reference types="vite/client" />
to the top of whatever file you're defining your glob in as shown in https://docs.convex.dev/testing/convex-test#custom-convex-folder-name-or-location (or in a pinch, add a // @ts-expect-error
comment above the line TypeScript is unhappy about)convex-test | Convex Developer Hub
The convex-test library provides a mock implementation of the Convex backend
That's correct, the advice in the docs now is what I did. Defining
test.setup.ts
:
And then importing modules
to use within the arguments of convexTest()
:
Would love if the library could be updated to avoid this for pnpm, definitely feels like extra boilerplate!@sshader getting the same problem still, and its not at all clear from the documentation that this needs to be done, pnpm is not mentioned at https://docs.convex.dev/testing/convex-test
convex-test | Convex Developer Hub
The convex-test library provides a mock implementation of the Convex backend
for anyone else who is trying to resolve this (including future me, again) - my workaround had to be tweaked a little.
I used this instead:
this can be affected if you're using a folder for tests that is not inside of the
convex
folder, in previous versions this had to be done because you couldn't export functions from a file in the convex folder that was not a proper convex function.
if you're willing to let go for pnpm safety to have a quick and dirty fix - you can just set node-linker=hoisted
inside of the .npmrc - although kinda defeats the purpose of using pnpm in the first place.