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)
@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.
@powerful23 Do you know the location to check for iOS? Thanks for the reply!
@jdeanwaite No I couldn't find where the module got hooked in IOS. But if you could check that in Android and find it do cause some problem, that would help a lot.
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:
node_modules/amazon-cognito-identity-js/ios/RNAWSCognito.xcodeproj to the Libraries folder in the XCode project. 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.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.
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?
@Der1906 haha yes that was simply a typo on this issue. I’ll update it. But yes, I was doing ‘react-native link’.
The problem was that react native told me that it linked iOS successfully, however it did not link the libraries in the XCode project. However, Android did link successfully from the same call.
Yes I did see #194, but as mentioned, linking automatically did not work, I had to manually link the iOS project.
I am having this issue as well. @jdeanwaite Are you having an ejecting app? or using expo?
@zt7584 I use an ejected app, with which are you experiencing the problem?
hey - what was the resolution for this issue. I am getting the same problem in android only (works fine in ios)
@BenjaminWatts after you link using
react-native link amazon-cognito-identity-js
try uninstalling your app in android and
react-native run-android
again.
@chrisgrg Thanks! This solution worked great for me
I'm still seeing the Cannot read property 'computeModPow' of undefined even after running react-native link amazon-cognito-identity-js and following the steps described by @jdeanwaite. Can anyone helo with this?
@pwaweru-mdsol can you verify that under your android/settings.gradle the amazon-cognito-identity-js is included?
@powerful23 ahh, should have mentioned this earlier! I had to remove the Pods directory and Podfile.lock file, and re-run Pod install. All working fine now!
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
return Arrays.
HERE
)
}
@jeanfour-corp Legend! That worked!
react-native link did not solve the problem, but running react-native link amazon-cognito-identity-js fixed it. Thx!
I tried everything above and was able to get it to work by opening xcode for the project and looked at the warnings and found one about cognito so I clicked it and it wanted me to update so I followed the prompts and then it worked.
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.
I faced this same issue with my iOS build. I had to unlink first.
react-native unlink amazon-cognito-identity-js
react-native link amazon-cognito-identity-js
Both amazon-cognito-identity-js and aws-amplify packages need to be installed?
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.
@15Cactus49 you are my hero today!
@MikaelStenstrand life saver!
Both
amazon-cognito-identity-jsandaws-amplifypackages 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.
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:
npm add amazon-cognito-identity-js
cd ios; pod install; cd ..
resolved the issue for me.
Thank you @tjjfv . This should be in the documentation somewhere right?
@justinwaite at this comment https://github.com/aws-amplify/amplify-js/issues/563#issuecomment-377733312 did u have to install amazon-cognito-identity-js or was the aws-amplify dependecy alone enough? because im unable to link amazon-cognito-identity-js as it says i have to make sure i have to have the package already installed in my node modules and present in my package.json. and after i install and link amazon-cognito-identity-js the computmodpow error is replaced by a "USER_ID_FOR_SRP" is undefined.
When I'm trying to import in MainApplication.java:
import com.amazonaws.RNAWSCognitoPackage;
...
new RNAWSCognitoPackage()
I'm getting cannot find error in Android Studio. How is possible to fix it?
I have already installed amazon-cognito-identity-js and liked it.
For anyone still having trouble with this https://www.npmjs.com/package/amazon-cognito-identity-js#install-for-react-native
Most helpful comment
For RN 0.60.4 for iOS using Cocoa Pods with a Podfile containing:
if
amazon-cognito-identity-idis not installed as a direct dependency of the npm project, it is not included independenciesin the output ofreact-native-configwhich is the basis for inclusion viause_native_modules.Just running
react-native link amazon-cognito-identity-jsresults in:The following:
resolved the issue for me.