amplify-js: Unable to use signIn - Cannot read property 'computeModPow' of undefined

Do you want to request a feature or report a bug? Report a Bug

What is the current behavior?

Unable to use signIn, fails with the error: Cannot read property 'computeModPow' of undefined

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than AWS Amplify.

I have read other issues regarding this that discuss linking amazon-cognito-identity-js. I have linked the library using react-native link amazon-cognito-identity-js, and it appears successful. However, when I try and use the signIn function, I still receive the error. Here are the logs from the link.

rnpm-install info Linking amazon-cognito-identity-js ios dependency
rnpm-install info Platform 'ios' module amazon-cognito-identity-js has been successfully linked
rnpm-install info Linking amazon-cognito-identity-js android dependency
rnpm-install info Platform 'android' module amazon-cognito-identity-js has been successfully linked

Tried uninstalling the app, restarting packagers and debugger, etc.

What is the expected behavior?

I expect the signIn function to work.

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?

These are the aws plugins that I currently have installed:

    "aws-amplify": "0.2.14",
    "aws-amplify-react-native": "0.2.7",
    "aws-appsync": "^1.0.3",
    "aws-appsync-react": "^1.0.2",
    "aws-sdk": "^2.173.0",

Here is my RN info:

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 8.10.0
  Yarn: 1.5.1
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: 16.3.0-alpha.1 => 16.3.0-alpha.1
  react-native: 0.54.2 => 0.54.2

Full logs with log level set to DEBUG

[DEBUG] 00:36.981 SignIn - Sign In for testuser
ConsoleLogger.js:84
TypeError: Cannot read property 'computeModPow' of undefined
YellowBox.js:82
    at BigInteger.nativeModPow [as modPow] (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:143326:18)
    at AuthenticationHelper.calculateA (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:143634:16)
    at AuthenticationHelper.getLargeAValue (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:143572:16)
    at new AuthenticationHelper (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:143554:12)
    at CognitoUser.authenticateUserDefaultAuth (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:145268:36)
    at CognitoUser.authenticateUser (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:145258:23)
    at /Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:153869:22
    at tryCallTwo (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:14110:7)
    at doResolve (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:14274:15)
    at new Promise (/Users/justin/VSCodeProjects/MissionaryTrainingApp/.vscode/.react/index.bundle:14133:5)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 31 (4 by maintainers)

Most upvoted comments

For RN 0.60.4 for iOS using Cocoa Pods with a Podfile containing:

...
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
...
use_native_modules!
...

if amazon-cognito-identity-id is not installed as a direct dependency of the npm project, it is not included in dependencies in the output of react-native-config which is the basis for inclusion via use_native_modules.

Just running react-native link amazon-cognito-identity-js results in:

error Unknown dependency. Make sure that the package you are trying to link is already installed in your "node_modules" and present in your "package.json" dependencies. Run CLI with --verbose flag for more details.

The following:

  • Running
npm add amazon-cognito-identity-js
cd ios; pod install; cd ..
  • Cleaning & Building

resolved the issue for me.

Okay so that was the problem: even though RN says it linked amazon-cognito-identity-js correctly, it did not link iOS correctly. To fix I did the following:

  1. opened the XCode project and dragged node_modules/amazon-cognito-identity-js/ios/RNAWSCognito.xcodeproj to the Libraries folder in the XCode project.
  2. Then I opened up Build Phases and dragged libRNAWSCognito.a to the Link Binary with Libraries section. This is found in XCode when you expand Libraries > RNAWSCognito.xcodeproj > Products.
  3. Recompiled the project and it works!

My next question would be: is this a React Native problem or potentially a problem with the amazon-cognito-identity-js library? I don’t personally know much about how linking is done. I haven’t had many issues with other libraries in this regard.

@BenjaminWatts after you link using react-native link amazon-cognito-identity-js try uninstalling your app in android and react-native run-android again.

For anybody running into this error using both, react-native-navigation and aws-amplify, you need to manually link the RNAWSCognitoPackage() in the MainApplication.java file:

protected List<ReactPackage> getPackages() {
      // Add additional packages you require here
      // No need to add RnnPackage and MainReactPackage
      return Arrays.<ReactPackage>asList(
          // eg. new VectorIconsPackage()
        new RNAWSCognitoPackage()

      );
  }

I spent countless hours fixing this, so I hope it helps someone.

Thanks @MikaelStenstrand . You saved my day.

@brickmaker17 I think you are using cocoa pods.

$ react-native link amazon-cognito-identity-js
$ cd ios
$ pod update && pod install

It works for me.

Both amazon-cognito-identity-js and aws-amplify packages need to be installed?

@grifotv No, @aws-amplify/auth has amazon-cognito-identity-js as a dependency; you just need to run react-native link amazon-cognito-identity-js.

react-native link did not solve the problem, but running react-native link amazon-cognito-identity-js fixed it. Thx!

@jdeanwaite this is often caused by some react-native link issues. One of the things you need to check is that whether this module is correctly linked in to the android/ios native module. For example, you can check the MainApplication.java under android/app/src/.../ to see there is one RNAWSCognitoPackage() under MainReactPackage. Hope that could help you.

did you try react-native link amazon-cognito-identity-js instead of npm link amazon-cognito-identity-js?

It’s related to #194 , did u check this?

After a very frustrating afternoon following everyone’s suggestions, the only fix I found was to add the following lines to my app’s MainApplication.java. I don’t know why linking didn’t automatically generate these lines properly, but I’m excited to move on to other bugs 😃

import com.amazonaws.RNAWSCognitoPackage; … new RNAWSCognitoPackage()

The first line obviously goes along with other imports, and the second gets included within: protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( HERE ) }

Both amazon-cognito-identity-js and aws-amplify packages need to be installed?