Amplify-js: null is not an object evaluating RNAWSCognito.-computeModPow)

Created on 8 Oct 2019  路  13Comments  路  Source: aws-amplify/amplify-js

Describe the bug
I'm getting an error: "null is not an object evaluating RNAWSCognito.-computeModPow)", when I'm trying to Log In

To Reproduce
Steps to reproduce the behavior:

  1. Create expo project
  2. Eject it to bare workflow project
  3. Add aws-amplify

Expected behavior
App works

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: all

Smartphone (please complete the following information):

  • Device: all
  • OS: all

Additional context
I'm getting this error, during the login process

Sample code
Include additional sample code or a sample repository to help us reproduce the issue. (Be sure to remove any sensitive data)

import { Auth } from 'aws-amplify'
const user = await Auth.signIn(realUser, password);

_You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app._

Auth React Native bug pending-close-response-required

Most helpful comment

This steps solved my problem:

npm install amazon-cognito-identity-js
then adding pod 'RNAWSCognito', :path => '../node_modules/amazon-cognito-identity-js' in Podfile
cd ios
pod install

All 13 comments

@Luckygirlllll Can you provide which versions of aws-amplify you are using and which versions of aws-amplify-react-native you are using?

@sammartinez I have tested 2 version of aws-amplify: 1.1.26 and 1.1.40, I got this error with both versions.
I don't use in the project aws-amplify-react-native

This steps solved my problem:

npm install amazon-cognito-identity-js
then adding pod 'RNAWSCognito', :path => '../node_modules/amazon-cognito-identity-js' in Podfile
cd ios
pod install

However, I still have an issue in Android

react-native link amazon-cognito-identity-js didn't help

@Luckygirlllll what version of react native are you using? Did you run react-native link, before it started working in iOS as well?

Either you have < 0.60 and need to use react-native link, but wont have to do pod install.

Or you have > 0.60 in which case there is autolinking enabled (do not do react-native link). In this case you need to do pod install for iOS and nothing for Android

@Luckygirlllll just out of curiosity, what version of expo are you using? As per the docs it seems the latest version of RN is 0.59.8.

I can try to reproduce this, but was curious if you have considered using the RN CLI to create the app since you are ejecting anyway.

Expo 35, I have created app using RN CLI as well, I was getting the same error there as well, I'm using react-native-unimosules in the project. If create expo project and then eject it, it will create project with react-native 0.59.10 by default.

@Ashish5591 Hey, is there any updates regarding this issue?

More info about this error:"Error: Unable to resolve moduleamazon-cognito-identity-jsfrom/Users/iryna/Documents/Projects/my_project/node_modules/@aws-amplify/auth/lib/Auth.js: Moduleamazon-cognito-identity-jsdoes not exist in the Haste module map
"

@Luckygirlllll I was able to get it working with ios and android with RN 0.59.10. I will add the detailed installation steps in a comment below so you can try that, but here is something you can try first with your existing project:
Make sure amazon-cognito-identity-js present in your node_modules. It should be present when you do yarn add aws-amplify. You should not have to install it yourself.

If it is present then lets try resetting everything once:
1) Unlink amazon-cognito-identity-js: react-native unlink amazon-cognito-identity-js
1) Delete node_modules: rm -rf node_modules
2) Remove amazon-cognito-identity-js if present from your package.json. Your dependencies should look something like:

"dependencies": {
    "aws-amplify": "^1.2.2",
    "react": "16.8.3",
    "react-native": "0.59.10"
  }

3) Install your dependencies again: npm install
5) Check that amazon-cognito-identity-js is present in your node_modules
6) Now link the dependency: react-native link amazon-cognito-identity-js
7) Start the packager and reset the cache: npm start -- --reset-cache
8) run the app: react-native run-android

Try this to see if it works, if not you can try a fresh project. I'll be adding all the steps in a comment below.

@Luckygirlllll were you able to resolve the issue? If not try the setup of a new project below:

Here are the setup steps to use Auth in a new React Native (0.59.10) project
1) Create the project using React Native CLI:
react-native init rnAuth59 --version 0.59.10
2) Go to the project root and do amplify init:
cd rnAuth59 && amplify init
3) Add Auth to you project using the CLI:
amplify add auth
(I have used the Default Configuration option for this project)
4) Create your resources in the cloud using amplify push:
amplify push
5) Add the amplify library to your project:
yarn add aws-amplify
6) At this point you should already have amazon-cognito-identity-js in your node_modules and you need to link the dependency (this is a RN project <0.60 so there is no autolinking) :
react-native link amazon-cognito-identity-js
7) Once the module has been linked, go ahead and run your project:
For iOS: react-native run-ios
For Android: react-native run-android

Once the app starts up you should be able to use the Auth APIs and talk to Cognito. Here is some sample code I tested for the app above:

async function signIn() {
  try  {
    const user = await Auth.signIn(username, password);
    console.log('USER', user);
  } catch (err) {
    console.log('Err: ', err);
  }
}

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@Luckygirlllll I had same issue on RN v0.61.5, and I posted how I solved.

Was this page helpful?
0 / 5 - 0 ratings