#Type error when following convex-test documentation

3 messages · Page 1 of 1 (latest)

vast pecan
#

In the documentation for convex-test (https://docs.convex.dev/testing/convex-test) under "If your Convex functions are in a directory other than convex" it states to create a "test.setup.ts" and copy and paste the code snippet. This snippets uses types from "vite/client".

When I have done this I get the following type errors in that file:

  1. Cannot find type definition file for 'vite/client'
  2. Property 'glob' does not exist on type 'ImportMeta'

Installing vite as a dev dependency (it's already included in vitest but doesn't resolve via my pnpm setup) resolves the types.

Could the documentation do with being updating to make this clear? Or is this a setup issue of mine and adding vite should not be required?

Mock Convex backend for fast automated testing of functions

latent heathBOT
#

Hi @vast pecan. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

You’re right that the snippet in the docs assumes Vite/Vitest-style globals, but the documentation doesn’t explicitly say you must have vite (and its types) installed.

The relevant section shows:

/// <reference types="vite/client" />
export const modules = import.meta.glob(
  "./**/!(*.*.*)*.*s"
);

and then uses modules with convexTest(schema, modules). [convex-test get-started]

From the docs alone:

  • They rely on /// <reference types="vite/client" />, which is what provides the ImportMeta augmentation and import.meta.glob. [convex-test get-started]
  • They don’t mention that you must install vite (or otherwise provide those types) if your project isn’t already using Vite.

So:

  • Your two errors (Cannot find type definition file 'vite/client' and Property 'glob' does not exist on type 'ImportMeta') are exactly what you’d expect in a non‑Vite project that copies this snippet as‑is.
  • Installing vite as a dev dependency (or otherwise adding the vite/client types) is a reasonable fix, but this requirement is not called out in the docs.

Based on the provided sources, there’s no explicit guidance about this edge case, so the documentation could indeed be clearer for non‑Vite setups (e.g. by stating that the snippet assumes Vite/Vitest and vite/client types, or by offering an alternative that doesn’t rely on import.meta.glob). The knowledge sources don’t say whether this is considered a docs bug vs. a setup issue, only how to wire modules when using Vite.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: