amazon-cognito-auth-js
amazon-cognito-auth-js copied to clipboard
[ts] Cannot find module 'amazon-cognito-auth-js'.
Hi Team,
I am trying to use "amazon-cognito-auth-js" inside my angular2 web application. Executed the following steps to add the dependencies.
- npm install --save amazon-cognito-auth-js
- 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
+1
It seems to be a typescript issue. This package does not have typescript support.
+1
+1
I seem to also be getting this issue without ts, using just the vanilla create react app.
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
+1111
Inspired by the solution given by @deeperid, I do const amazonCognitoAuth: any = require("amazon-cognito-auth-js/dist/amazon-cognito-auth");
If the project has React structure, then this will work: import { CognitoAuth } from 'amazon-cognito-auth-js/dist/amazon-cognito-auth';
Is the plan to fix this? It's not intuitive to have to use that workaround.
@dpwrussell yes we are on track of fixing this! Thanks.
Currently, this workaround works because the bundled auth SDK file is under /dist directory.
@yuntuowang I have tried that. It does not work in Ionic+angular+typescript Mobile Project.
Any suggestions?