aws-sdk-js icon indicating copy to clipboard operation
aws-sdk-js copied to clipboard

fail to build in angular 12 when using aws-sdk/clients/cognitoidentityserviceprovider

Open tahirmolkar opened this issue 4 years ago • 6 comments

I am getting following error when try to build my project in angular I have used this to list cognito users so when we comment out code regarding this library then angular builds successfully

Error: Optimization error [8029-es2017.561d40d2ba468e9af625.js]: Error: Transform failed with 1 error: 8029-es2017.561d40d2ba468e9af625.js:131:5: error: Expected identifier but found "=" at failureErrorWithLog (D:\Node\workspace-framework - Copy\node_modules\esbuild\lib\main.js:1449:15) at D:\Node\workspace-framework - Copy\node_modules\esbuild\lib\main.js:1260:29 at D:\Node\workspace-framework - Copy\node_modules\esbuild\lib\main.js:609:9 at handleIncomingPacket (D:\Node\workspace-framework - Copy\node_modules\esbuild\lib\main.js:706:9) at Socket.readFromStdout (D:\Node\workspace-framework - Copy\node_modules\esbuild\lib\main.js:576:7) at Socket.emit (node:events:394:28) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at Socket.Readable.push (node:internal/streams/readable:228:10) at Pipe.onStreamRead (node:internal/stream_base_commons:199:23)

following is my code

import AWS from 'aws-sdk/global'; import CognitoIdentityServiceProvider from 'aws-sdk/clients/cognitoidentityserviceprovider';

@Component({ selector: 'vex-forgot-password', templateUrl: './forgot-password.component.html', styleUrls: ['./forgot-password.component.scss'], animations: [fadeInUp400ms], }) export class ForgotPasswordComponent {

cognitoIdentityServiceProvider: any;

constructor(private router: Router) { let conf = new AWS.Config({ accessKeyId: environment.AccessKeyId, secretAccessKey: environment.SecretAccessKey, region: environment.Region, });

this.cognitoIdentityServiceProvider = new CognitoIdentityServiceProvider(
  conf
);

}

sendCode = (model) => { let that = this;

const params = {
  UserPoolId: environment.UserPoolId,
  AttributesToGet: ['email'],
  Filter: 'email="' + model.usernameOrEmail + '"',
};
this.cognitoIdentityServiceProvider.listUsers(params, (err, userList) => {
  if (err) {
    console.log('Please Try Again Later');
    return;
  }

  if (userList.Users.length === 0) {
    console.log('User Not Exsits');
    return;
  }

  that.cognitoIdentityServiceProvider.forgotPassword(
    {
      ClientId: environment.ClientId,
      Username: userList.Users[0].Username,
    },
    function (err, data) {
      if (err) {
        console.log(err)
        return;
      }
    }
  );
});

};

}

tahirmolkar avatar Nov 24 '21 07:11 tahirmolkar

Same issue as described at https://stackoverflow.com/questions/70041745/webpack-external-module-gives-an-error-on-optimization if it helps. The Stack Overflow question has more details.

sheridansmall avatar Nov 29 '21 14:11 sheridansmall

Currently experiencing the same issue. Is there a solution yet? Downgrading to the version proposed in the stackoverflow issue unfortunately didn't solve it for me. Using aws-sdk 2.1046 with angular 13

mhilgefort avatar Dec 16 '21 08:12 mhilgefort

Simply call the list user API manually

tahirmolkar avatar Dec 16 '21 17:12 tahirmolkar

try to reduce the version of amazon-cognito-identity-js to "^3.3.3"

YoannR09 avatar Jan 19 '22 12:01 YoannR09

Experienced the same problem after upgrading ng v11 -> 12. "amazon-cognito-identity-js": "^5.2.4",

Downgraded to "^3.3.3" (latest stable version) and error has resolved.

DanielLMA avatar Feb 09 '22 00:02 DanielLMA

@DanielLMA apologies the issue fell out of queue. https://www.npmjs.com/package/amazon-cognito-identity-js seems to be handled by https://github.com/aws-amplify/amplify-js

ajredniwja avatar Jul 25 '22 18:07 ajredniwja

Closing this issue now, please open a new issue if any other questions.

ajredniwja avatar Aug 22 '22 08:08 ajredniwja