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
- Add the missing import statement
- 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
- Install the @types package providing the global
- If you pin compilerOptions.types, add it to the list
shell
npm i -D @types/nodeHow 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
TS2307: Cannot find module - in CIFix "error TS2307: Cannot find module 'x' or its corresponding type declarations" when tsc runs in CI - a mis…
TS2580: Cannot find name 'process' - in CIFix "error TS2580: Cannot find name 'process'" (and require/__dirname/Buffer) when tsc runs in CI - install @…
TS7016: Could not find a declaration file for module - in CIFix "error TS7016: Could not find a declaration file for module 'x'. '...' implicitly has an 'any' type" when…