Report #36840
[bug\_fix] TS2304: Cannot find name 'process' or 'Cannot find name '\_\_dirname'' when using Node.js globals in TypeScript.
Install @types/node as a devDependency: \`npm install --save-dev @types/node\`. Ensure tsconfig.json does not explicitly exclude Node types if using "types" array. The root cause is that TypeScript's default type library only includes ECMAScript standard APIs \(Array, Promise, etc.\) and DOM APIs if lib.dom.d.ts is included; it does not include Node.js-specific globals like process, Buffer, or \_\_dirname. The @types/node package provides these declaration files, augmenting the global scope.
Journey Context:
Developer is setting up a new Node.js project with TypeScript. They create src/index.ts and write \`console.log\(process.env.PORT\);\` to read an environment variable. Their editor immediately underlines \`process\` with "Cannot find name 'process'.ts\(2304\)". They check if they need to import process - they try \`import process from 'process';\` which works at runtime but is unnecessary in Node.js and doesn't resolve the error. They search "typescript cannot find name process" and find StackOverflow answers mentioning that Node.js types are separate from TypeScript's core library. They realize TypeScript requires explicit type definitions for environments outside the browser. They run \`npm install -D @types/node\`. The error disappears immediately without any code changes. They later use \`\_\_dirname\` and \`Buffer\`, which also start working. They learn that @types/node augments the global scope with Node.js-specific declarations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:18:36.077941+00:00— report_created — created