Amazon-cognito-identity-js: error cannot find name 'Buffer

Created on 27 Jun 2017  路  4Comments  路  Source: amazon-archives/amazon-cognito-identity-js

I am developing a Nodejs mobile app using Ionic, Angular 2 and Aws Cognito. After integrating amazon-cognito-identity-js, it shows error cannot find name 'Buffer'

AWS Cognito installed using the command: npm install --save amazon-cognito-identity-js

After adding following statement:
import { CognitoUserPool, CognitoUserAttribute, CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js'

getting the following error:
Cannot find name 'Buffer'.
L1031: export type _Blob = Buffer|Uint8Array|Blob|string;
L1032: export type Boolean = boolean;

Most helpful comment

@RashmiPandey Double check your tsconfig.json file's typeRoots and types. If typeRoots is declared, it needs to have "node_modules/@types" included. If types is defined it needs to have "node" included. More in-depth explanation here with reference to tsconfig documentation. You'll also want to make sure you've installed the Node Typescript definitions module: npm install --save-dev @types/node

{
    "compilerOptions": {
        "typeRoots": [ "node_modules/@types" ],
        "types": [ "node" ]
    }
}

amazon-cognito-identity-js brings in aws-sdk as a dependency but the issue is Buffer and other Node specific types that amazon-cognito-identity-js references aren't being found.

All 4 comments

How are you getting the main aws sdk and what version are you getting?

@RashmiPandey Double check your tsconfig.json file's typeRoots and types. If typeRoots is declared, it needs to have "node_modules/@types" included. If types is defined it needs to have "node" included. More in-depth explanation here with reference to tsconfig documentation. You'll also want to make sure you've installed the Node Typescript definitions module: npm install --save-dev @types/node

{
    "compilerOptions": {
        "typeRoots": [ "node_modules/@types" ],
        "types": [ "node" ]
    }
}

amazon-cognito-identity-js brings in aws-sdk as a dependency but the issue is Buffer and other Node specific types that amazon-cognito-identity-js references aren't being found.

@nwayve Had the same issue, your solution was the only one worked for me.

Hi guys! I am facing the same issue. Please help me fix this issue:

Typescript Error
Cannot find name 'Buffer'.

聽 | export type CertificateBody = string;
聽 | export type CertificateBodyBlob = Buffer\|Uint8Array\|Blob\|string;
聽 | export type CertificateChain = string;

Was this page helpful?
0 / 5 - 0 ratings