Getting error TS2304: Cannot find name 'Buffer'

后端 未结 5 1607
Happy的楠姐
Happy的楠姐 2020-12-08 06:38

I am trying to do base64 encode in NodeJS using TypeScript.

Following code working fine in JavaScript.

When I am writing same thing in TypeScript and compil

5条回答
  •  佛祖请我去吃肉
    2020-12-08 07:20

    Buffer is from Node namespace. First install

    npm install --save @types/node

    then add below code to your tsconfig.json file inside the compilerOptions section

    "types": ["node"],
    "typeRoots": ["node_modules/@types"]
    

    The typeRoots entry specifies a list of directories for type definition files to be included. It requires TypeScript version 2.0 or later.

提交回复
热议问题