Klexik
Klexik2mo ago

Deno compile with @types/node (Buffer) issue

Hi, I am trying to get Deno to compile my node.js project and I am hitting the wall with typechecking (I know about --no-check, I just want to resolve this) Error: TS2580 [ERROR]: Cannot find name 'Buffer'. return { out: Buffer.from(out).toString('hex'), result }; After some googling, I found there should be workaround https://docs.deno.com/runtime/fundamentals/node/#including-node-types But unfortunalty the documentation mention is extremly vague. Including /// <reference types="npm:@types/node" /> in top of my files does nothing, including it on top index.d.ts / buffer.d.ts in @types/node does nothing. Did anyone had similiar issue / have knowledge how to resolve this?
Deno
Node and npm Compatibility
Guide to using Node.js modules and npm packages in Deno. Learn about compatibility features, importing npm packages, and differences between Node.js and Deno environments.
4 Replies
marvinh.
marvinh.2mo ago
Looks like you're running into this issue: https://github.com/denoland/deno/issues/30138 Does adding this line to deno.json help?
{
"unstable": ["node-globals"],
}
{
"unstable": ["node-globals"],
}
Klexik
KlexikOP2mo ago
Thank you, I will check tomorrow. One thing that actually worked was adding import {Buffer} from ‘node:buffer’; but I need to validate tomorrow that this did not break node.js side of the project 🙂 This does not help, but I think generic advice should be to use the imports even if node does not require them. Thank you for your respone though 🙂
marvinh.
marvinh.2mo ago
We do expose node globals by default. Maybe it's just that we don't expose node types automatically. Another thing to try is to install @types/node to your dependencies (deno install npm:@types/node ) and see if that fixes it
Klexik
KlexikOP2mo ago
It did not I am using deno workspaces so that could be one of the reasons

Did you find this page helpful?