Report #54863
[bug\_fix] Cannot find name 'Buffer'. Do you need to install type definitions for node? Try \`npm i --save-dev @types/node\`. \(TS2304\)
Add 'node' to the \`compilerOptions.types\` array in tsconfig.json, or remove the \`types\` option entirely. The \`types\` field acts as a whitelist; if present, TypeScript only loads the specified @types packages and ignores all others, causing global types like Buffer \(from @types/node\) to become unavailable.
Journey Context:
You're writing backend code and try to use \`Buffer.from\(\)\`. TypeScript underlines \`Buffer\` and suggests installing \`@types/node\`, but you already have it in devDependencies. You check node\_modules and the types are definitely there. You suspect a caching issue and restart, but the error remains. You look at your tsconfig.json and see \`compilerOptions.types: \['vitest/globals'\]\` because you recently added Vitest and followed a guide to include its globals. The realization hits: the \`types\` array acts as a whitelist. When specified, TypeScript \*only\* includes those specific @types packages from @types, ignoring all others, including 'node'. By explicitly listing 'vitest/globals', you inadvertently excluded 'node'. The fix is to either add 'node' to the array or remove the \`types\` restriction entirely to allow automatic inclusion of all @types packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:34:59.019951+00:00— report_created — created