aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.6k stars 1.55k forks source link

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

Closed tahirmolkar closed 2 years ago

tahirmolkar commented 2 years ago

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;
      }
    }
  );
});

};

}

sheridansmall commented 2 years ago

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.

mhilgefort commented 2 years ago

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

tahirmolkar commented 2 years ago

Simply call the list user API manually

YoannR09 commented 2 years ago

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

DanielLMA commented 2 years ago

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.

ajredniwja commented 2 years ago

@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 commented 2 years ago

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