Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_aws_cognito_srp_client.default is not a constructor... #2

Open
tvanriper opened this issue Mar 21, 2023 · 4 comments
Open

import_aws_cognito_srp_client.default is not a constructor... #2

tvanriper opened this issue Mar 21, 2023 · 4 comments

Comments

@tvanriper
Copy link

Following README.md directly with:

import Srp from 'aws-cognito-srp-client';

const srp = new Srp(USERPOOLID);

When I run this in my dev environment, everything works very well. Very pleased with it.

When I run this within a lambda function in AWS, an exception is thrown reading:

err: TypeError: import_aws_cognito_srp_client.default is not a constructor

I don't know if it's helpful, but lambda runs nodejs v16.12. My dev environment run v16.19.0. I have not tried changing the dev environment to an earlier version of nodejs to see if that's the difference.

@tvanriper
Copy link
Author

tsc --version on my dev box gives me:

Version 4.9.5

But considering this gets compiled in my dev environment, I would think it should Just Work in Lambda. Very stumped.

@tvanriper
Copy link
Author

I've submitted a pull request, but I'm still experiencing problems. Namely, when I use this in my dev environment with the modifications I've submitted in my pull request, the polyfill fails to find a native crypto.

The reason for this is best explained here:

https://codedamn.com/news/javascript/fix-require-is-not-defined

Note where it states:

The "require()" function and the import/export syntax for ES6 modules cannot be combined within a single project. One or the other must be used consistently.

So I tried modifying the cryptoUtils.ts code to have the following at the top:

import * as cryptonite from "crypto";

Then, within the polyFillCrypto function, I placed the following:

if (typeof cryptonite !== "undefined") {
  return cryptonite;
}

But then, what is the point of the polyfill? Is it possible to remove polyFillCrypto and the const crypto = polyFillCrypto(); line altogether and use this at the top of the file:

import * as crypto from "crypto";

I don't quite know enough about what this area of the code is intending to know if this is the most correct way to handle this. I'm also not familiar enough with TS/JS to know if any of this is quite right.

@Raaghu
Copy link
Collaborator

Raaghu commented Mar 23, 2023

I would like to know more on how you deploy code to lambda ? are you using any frameworks or manually copying ?

@tvanriper
Copy link
Author

For this code, I'm using sveltekit-adapter-aws.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants