amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
423 stars 232 forks source link

[ts] Cannot find module 'amazon-cognito-auth-js'. #39

Open chanduchama opened 6 years ago

chanduchama commented 6 years ago

Hi Team,

I am trying to use "amazon-cognito-auth-js" inside my angular2 web application. Executed the following steps to add the dependencies.

  1. npm install --save amazon-cognito-auth-js
  2. import {CognitoAuth} from 'amazon-cognito-auth-js';

I see that the dependencies are updated in package.json. This is how it look inside my package.json file.

"amazon-cognito-auth-js": "^1.0.0", "amazon-cognito-identity-js": "^1.19.0", "aws-sdk": "^2.6.0",

Web app is generated using angualr cli. But while building the application i am receiving the following error. "[ts] Cannot find module 'amazon-cognito-auth-js'."

Can someone help me to resolve this?

Regards, Sarath

pabloow commented 6 years ago

+1

itrestian commented 6 years ago

It seems to be a typescript issue. This package does not have typescript support.

joeswiggin commented 6 years ago

+1

luomavaltteri commented 6 years ago

+1

stvnksslr commented 6 years ago

I seem to also be getting this issue without ts, using just the vanilla create react app.

deeperid commented 6 years ago

In package.json: "main": "lib/index.js", "module": "es/index.js", Are nowhere to be found in amazon-cognito-auth, so I used:

import { CognitoAuth } from 'amazon-cognito-auth-js/dist/amazon-cognito-auth';

To work around the incorrect values in package.json for now

bhao-speedline commented 6 years ago

+1111

bhao-speedline commented 6 years ago

Inspired by the solution given by @deeperid, I do const amazonCognitoAuth: any = require("amazon-cognito-auth-js/dist/amazon-cognito-auth");

yuntuowang commented 6 years ago

If the project has React structure, then this will work: import { CognitoAuth } from 'amazon-cognito-auth-js/dist/amazon-cognito-auth';

dpwrussell commented 6 years ago

Is the plan to fix this? It's not intuitive to have to use that workaround.

yuntuowang commented 6 years ago

@dpwrussell yes we are on track of fixing this! Thanks.

Currently, this workaround works because the bundled auth SDK file is under /dist directory.

engharb commented 5 years ago

@yuntuowang I have tried that. It does not work in Ionic+angular+typescript Mobile Project.

Any suggestions?