`Missing "./_generated/server" specifier in "convex" package` when testing
I am attempting to set up testing in Convex following the testing guide (https://docs.convex.dev/functions/testing) but am getting the following error after writing my first test.
it's reproducible with only the following, and I don't know what the error is telling me:
9 Replies
What does the rest of your project look like?
The unusual thing happening here is that vitest is looking for "./_generated/server" in the convex package instead of in the convex directory.
to figure out why, I'm wondering if you
- have surprising files in your convex directory like a package.json
- have a different tsconfig.json settings than expected
- have some path aliases defined
but if it's possible to share your code that might be quickest
(and thanks for letting us know! this testing guide is new, we're probably not accounting for all the different ways a project can be set up yet)
Oh those are good tips
* no package.json in the convex/ directory. there's a package.json at the root and all Convex-related files are in the convex/ directory also at the root
* the project does have tsconfig.json vs. tsconfig.node.json for Vite's different environments
* the project aliases "@/" to the "./src" directory
^ that's in vite.config.ts
in tsconfig there is the following:
Vitest claims to use
resolve.alias
from the Vite config: https://vitest.dev/config/#alias
I'm more familiar with React and Jest than Vue and Vite. I appreciate the helpfor some quick debugging, anything different if you replace
.
with ../convex
in that import?
Or add a file extension .js to that one and the schema one?the
../convex
didn't change the error
^ same error
^ same here too
Thanks for trying these, I just guessing at how to get around this confusion. If you could share your code or make a copy and rip out the private parts to repro I'd love to see
okay I may have tracked it down. I started binary searching through schema.ts by commenting stuff out. there was one table schema defined in a separate file
userSettings.ts
schema.ts
might be those funky paths. unsure why they are importing from "convex/" instead of "./"
yes that seems to be it. I don't know why those paths were
"convex/.."
or even how they were working? I changed them to "../.."
and now it looks like the error is goneoh that must have been it, yeah
convex is both a package and a directory, possibly something to change someday if this kind of path aliasing gets more popular
schema is especially tough because convex/schema is an entry point and ./convex/schema.ts is a file
My guess is that it's a difference between esbuild config used by Convex and esbuild config used by Vitest. The first one ignored the invalid unused paths, the second one threw an error.
thank you both for commenting. @ballingt, your initial comment is what made me start looking at the imports in schema.ts and sent me searching in the right spot