Skip to content
Latchkey

TS2304: Cannot find name - in CI

tsc encountered an identifier it has no declaration for in scope.

What this error means

Type-checking fails with TS2304 naming an identifier such as a missing import, a DOM global, or a type that was never declared.

tsc
src/dom.ts(5,12): error TS2304: Cannot find name 'document'.

Common causes

How to fix it

Import the symbol or add the lib

  1. Add the missing import statement
  2. If it is a browser global, include "dom" in compilerOptions.lib
tsconfig.json
{
  "compilerOptions": {
    "lib": ["ES2022", "DOM", "DOM.Iterable"]
  }
}

Install and include the types package

  1. Install the @types package providing the global
  2. If you pin compilerOptions.types, add it to the list
shell
npm i -D @types/node

How to prevent it

  • Set compilerOptions.lib to match your runtime and avoid an over-restrictive types allowlist that hides installed globals.

Frequently asked questions

What causes "TS2304 cannot find name"?
Type-checking fails with TS2304 naming an identifier such as a missing import, a DOM global, or a type that was never declared.
How do I fix TS2304 cannot find name?
Import the symbol or add the lib

Related guides

References

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