TypeScript: Cannot find name 'process'
The Node global types are not loaded. Either @types/node is missing, or the compilerOptions.types array is set, which switches off automatic inclusion of every other @types package and quietly removes them from the compilation.
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
npm i -D @types/node
// tsconfig.json: an explicit types array is an allowlist, not an addition
{
"compilerOptions": {
"types": ["node", "vitest/globals"]
}
}
// Browser code should not use process at all
import.meta.env.VITE_API_URL // Vite
process.env.NEXT_PUBLIC_API_URL // Next.js inlines this at build time
# Confirm the types were resolved
npx tsc --traceResolution | grep -i '@types/node'
How to diagnose TypeScript errors
TypeScript errors are the compiler describing a mismatch between what you declared and what you did. Nearly all of them fall into assignability (this shape is not that shape), missing declarations (a JavaScript package with no types), or strict null checks (a value can be undefined on a path you did not handle). Casting with as or any silences the message without fixing the underlying mismatch, which usually reappears at runtime.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Read the error from the innermost "Types of property X are incompatible" line outward. That nested line names the actual mismatch.
- For missing declarations, try
npm i -D @types/<pkg>first; if none exists, write a minimal.d.tsrather than reaching forany. - Narrow rather than assert. A type guard, an
incheck, or an early return preserves safety whereasdiscards it. - Use
tsc --noEmit --prettyto check the whole project; editors sometimes use a different TypeScript version than the build. - Check
strict,skipLibCheckandmoduleResolutionin tsconfig when errors appear only in CI or only in the editor.
Tools worth reaching for
tsc --noEmitts-node / tsx@types/* packagestypescript-eslinteditor TS version selector
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related TypeScript errors
- TypeScript: 'error' is of type 'unknown' (TS18046)Since TypeScript 4.4, useUnknownInCatchVariables (part of strict) types the catch binding as…
- TypeScript: Argument of type X is not assignable to parameter of type YA function argument's type doesn't match the parameter's declared type. Common when passing…
- TypeScript: Cannot find module './x.js' or its corresponding type declarationsWith module set to node16 or nodenext, TypeScript resolves imports exactly as Node does at…
- TypeScript: Cannot redeclare block-scoped variable 'name'A file with no import or export is treated as a script, not a module, so its top level…
- TypeScript: Cannot use JSX unless the '--jsx' flag is providedA .tsx file was compiled with JSX support off. Either the option is missing, or the editor is…
- TypeScript: Could not find a declaration file for moduleA JS library has no TypeScript type declarations. The library has no built-in types and no…
- TypeScript: Module can only be default-imported using the 'esModuleInterop' flagThe package is CommonJS and sets module.exports directly, so it has no ES default export to…
- TypeScript: No overload matches this callNone of the function's overload signatures match the provided arguments. The argument types…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.