Skip to content
Latchkey

TypeScript "TS2688: Cannot find type definition file for" - Fix in CI

Your compilerOptions.types (or a typeRoots entry) names a type package that is not installed. tsc looks for node_modules/@types/<name> (or the typeRoots path), does not find it, and raises TS2688 at config load.

What this error means

Type-checking fails before checking your code with error TS2688: Cannot find type definition file for '<x>'., naming the entry from your types array or typeRoots.

tsc output
error TS2688: Cannot find type definition file for 'jest'.
  The file is in the program because:
    Entry point of type library 'jest' specified in compilerOptions

Common causes

types array names an uninstalled package

A compilerOptions.types: ["jest", "node"] allowlist names a package whose @types/* is not installed, so tsc cannot find its definition file.

typeRoots points at a missing path

A custom typeRoots entry references a directory that does not exist in CI (e.g. a local types folder not committed), so the named type cannot be located.

How to fix it

Install the named type packages

Add every package listed in types as a dev dependency.

Terminal
npm install -D @types/jest @types/node

Fix or remove the types/typeRoots entry

Only list type packages you actually install, and point typeRoots at real paths.

tsconfig.json
// tsconfig.json
{ "compilerOptions": { "types": ["node", "vite/client"] } }

How to prevent it

  • Install @types/* for every entry in compilerOptions.types.
  • Point typeRoots only at directories that exist in CI.
  • Avoid an over-restrictive types allowlist you do not keep in sync.

Frequently asked questions

What causes ""TS2688: type definition file""?
A compilerOptions.types: ["jest", "node"] allowlist names a package whose @types/* is not installed, so tsc cannot find its definition file.
How do I fix "TS2688: type definition file"?
Add every package listed in types as a dev dependency.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card