Report #8144
[bug\_fix] TS2304: Cannot find name 'fetch' / Cannot find name 'ResizeObserver'
Add 'DOM' to the 'lib' array in tsconfig.json compilerOptions \(e.g., 'lib': \['ES2020', 'DOM'\]\). The 'target' option only includes built-in ECMAScript APIs, not host environment APIs like the browser's DOM or Node's 'Buffer'.
Journey Context:
You're writing a React application that uses the native 'fetch' API to call your backend. You've set 'target': 'ES2020' in your tsconfig.json assuming it includes all modern browser APIs. TypeScript underlines 'fetch' with 'Cannot find name fetch'. You think maybe you need to install '@types/node' because you're used to Node types. That doesn't help. You try declaring 'global \{ interface Window \{ fetch: any \} \}' but that's hacky. You search 'typescript fetch cannot find name' and find a StackOverflow answer explaining that 'target' only controls the ECMAScript language version \(Promise, Array, etc.\), while browser-specific APIs like fetch, window, or ResizeObserver are part of the 'DOM' library. You open tsconfig.json and add 'lib': \['ES2020', 'DOM', 'DOM.Iterable'\]. The error immediately resolves because TypeScript now loads the type definitions for browser globals.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:44:22.194329+00:00— report_created — created