aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

null is not an object (evaluating RNAWSCognito.computeModPow) #3682

Closed kirkryan closed 5 years ago

kirkryan commented 5 years ago

Describe the bug I hope this saves someone some time (and frustration)

A user can sign up or view the login page, but upon login, the following error is observed:

null is not an object (evaluating RNAWSCognito.computeModPow)

To Reproduce Create new >=RN0.60.0 project cd ios pod install build

Expected behavior Amplify podspec should correctly list RNAWSCognito.

Smartphone (please complete the following information):

Additional context remember not to use react-native link when working in >=0.60.0

Fix simply run the following in your project root

yarn add amazon-cognito-identity-js
cd ios
pod install
haverchuck commented 5 years ago

@kirkryan - Thanks for posting this. Can you post a little bit of detail on how you've configured your app? Are you using the aws-amplify-react-native authenticator component?

kirkryan commented 5 years ago

@haverchuck - that’s correct. This is when using the withAuthenticator HOC on iOS builds.

haverchuck commented 5 years ago

@kirkryan - Thanks. I think this is an expected step, but we need to update our docs.

BradyShober commented 5 years ago

I have also run into this issue but when trying to use the recommended fix, I get a duplicate symbols Linker Error. In my app we are not using aws-amplify-react-native component. The specific error is

duplicate symbol _OBJCCLASS$_JKBigInteger in: /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/JKBigInteger2/libJKBigInteger2.a(JKBigInteger.o) /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/libRNAWSCognito.a(JKBigInteger.o) duplicate symbol _OBJCMETACLASS$_JKBigInteger in: /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/JKBigInteger2/libJKBigInteger2.a(JKBigInteger.o) /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/libRNAWSCognito.a(JKBigInteger.o) duplicate symbol _OBJCIVAR$_JKBigInteger.m_value in: /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/JKBigInteger2/libJKBigInteger2.a(JKBigInteger.o) /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/libRNAWSCognito.a(JKBigInteger.o) duplicate symbol _OBJCIVAR$_JKBigDecimal.bigInteger in: /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/JKBigInteger2/libJKBigInteger2.a(JKBigDecimal.o) /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/libRNAWSCognito.a(JKBigDecimal.o) duplicate symbol _OBJCCLASS$_JKBigDecimal in: /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/JKBigInteger2/libJKBigInteger2.a(JKBigDecimal.o) /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/libRNAWSCognito.a(JKBigDecimal.o) duplicate symbol _OBJCMETACLASS$_JKBigDecimal in: /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/JKBigInteger2/libJKBigInteger2.a(JKBigDecimal.o) /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/libRNAWSCognito.a(JKBigDecimal.o) duplicate symbol _OBJCIVAR$_JKBigDecimal.figure in: /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/JKBigInteger2/libJKBigInteger2.a(JKBigDecimal.o) /Users/brady/Library/Developer/Xcode/DerivedData/traduki-ekuctotjpfcwpphgyaufmdogypjm/Build/Products/Debug-iphonesimulator/libRNAWSCognito.a(JKBigDecimal.o) ld: 7 duplicate symbols for architecture x86_64

kirkryan commented 5 years ago

Run react-native unlink . Maybe it’s being imported twice after doing a react-native link (stay away from doing this in RN >=0.60.0. Also check in Xcode that it’s not listed in your project root / libraries, if so remove the reference. Also, check your pod file to ensure it’s not listed twice.

BradyShober commented 5 years ago

It was not linked, not listed under libraries, and not listed at all in the pod file. libRNAWSCognito.a was listed under frameworks that I tried removing but that didn't help.

kirkryan commented 5 years ago

Did you remove it, then clean the build folder, then try to rebuild?

BradyShober commented 5 years ago

Yes I did clean before trying to rebuild.

kirkryan commented 5 years ago

I’ve just spotted that you mentioned it’s not in your pod file - that’s explains it. I had to manually add it:

#pod 'RNAWSCognito', :path => '../node_modules/amazon-cognito-identity-js'

haverchuck commented 5 years ago

@kirkryan Does a simple pod install from your ios directory resolve this?

kirkryan commented 5 years ago

@haverchuck It does once you’ve added it to your pod file yeah!

BradyShober commented 5 years ago

It still is giving the same error after I added it and ran pod install and also cleaned before rebuilding

BradyShober commented 5 years ago

It seems my issue was with Xcode keeping old derived data, after clearing everything in DerivedData it built fine. Also I have it running fine without it in the podfile because autolinking is working fine.

kirkryan commented 5 years ago

@BradyShober - nice, I’ll add that to my ever growing list of tricks and fixes

Ashish-Nanda commented 5 years ago

@BradyShober- glad you got it working! Just to confirm, you did not need to add it to your podfile, but running pod install from the ios directory is still a necessary step?

BradyShober commented 5 years ago

@Ashish5591 Correct, as long as you've updated successfully to RN 0.60 or higher and have require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' and use_native_modules! in your podfile autolinking should be working. You do still need to run pod install from the ios directory.

sammartinez commented 5 years ago

@kirkryan I ended up making a call out of this on our docs about this and the workaround. Please see the above PR that was merged. Closing issue as the workaround resolves this issue

bangersandflash commented 5 years ago

This fix works for me and I can successfully build the project in Xcode. I can also run the project on the simulator via Xcode but if I try to use react-native run-ios I get the duplicate symbols error that @BradyShober mentioned above. Any ideas?

BradyShober commented 5 years ago

@bangersandflash Try to delete the contents of your Xcode DerivedData folder, which you can get to following the instructions here https://stackoverflow.com/questions/46468220/how-can-i-delete-derived-data-in-xcode-9 (Instructions are for Xcode 9 but it still works the same for 10). After I did that, the duplicate symbols error was fixed.

bangersandflash commented 5 years ago

Thanks @BradyShober I've tried deleting the DerivedData contents and I'm still getting the same error. To be clear, I can build the Xcode project without any issues and run/debug it through Xcode.

I'm only seeing the compilation error when I try to run react-native run-ios from Terminal.

claudioviola commented 5 years ago

Same issue of @BradyShober Any solution?

Luckygirlllll commented 4 years ago

I have the same error both in Android and IOS, any updates regarding this error? "react-native": "0.59.10", I have tried fixe which was mention above, but it didn't help me.

Luckygirlllll commented 4 years ago

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
Luckygirlllll commented 4 years ago

However, I still have a problem with Android, I'm still getting an error there, react-native link amazon-cognito-identity-js didn't help

Luckygirlllll commented 4 years ago

@Ashish5591 0.59.10, in IOS it started to work without react-native link

jimbol commented 4 years ago

@bangersandflash Did you ever get it working when running react-native run-ios from Terminal.

nghabaoduy commented 4 years ago

Anyone have this issue?

Downloading dependencies Installing JKBigInteger2 (0.0.5)

[!] Error installing JKBigInteger2 [!] /usr/bin/git clone https://github.com/astruts/JKBigInteger.git /var/folders/4c/prj_vdcs0ln44y4sxdp_vp300000gp/T/d20191105-23642-e4nnc1 --template= --single-branch --depth 1 --branch 0.0.5

Cloning into '/var/folders/4c/prj_vdcs0ln44y4sxdp_vp300000gp/T/d20191105-23642-e4nnc1'... fatal: unable to access 'https://github.com/astruts/JKBigInteger.git/': Failed to connect to 10.210.250.7 port 8080: Operation timed out

janoist1 commented 4 years ago

I'm still having this issue even after adding pod manually as mentioned above. @Luckygirlllll how did you manage to make it work on ios?

Luckygirlllll commented 4 years ago

@janoist1 Try to delete Derived data from Xcode and try once again, also check if there is any errors during pod install

janoist1 commented 4 years ago

@Luckygirlllll thanks for being so quick with response! /Users/ist1/Library/Developer/Xcode/DerivedData is empty. There were no errors during pod install. I'm using Xcode Version 11.2.1 (11B500) React: 0.61.

Luckygirlllll commented 4 years ago

@janoist1 Check whether or not linking is correct in your IOS project for aws-amplify

janoist1 commented 4 years ago

@Luckygirlllll Ultimate fix for RN60+: pod 'RNAWSCognito', :path => '../node_modules/amazon-cognito-identity-js' must not be added to Podfile manually.

geoseong commented 4 years ago

I had same issues with the following dependencies,

"dependencies": {
    "aws-amplify": "^2.2.0",
    "aws-amplify-react-native": "^2.2.3",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-gesture-handler": "^1.5.2",
    "react-native-reanimated": "^1.4.0",
    "react-native-screens": "^2.0.0-alpha.22",
    "react-navigation": "^4.0.10"
}

testing on Android Emulator

I just tried $ yarn add amazon-cognito-identity-js, and error disappeared.

testing on iOS Simulator

got error first, (you can just ignore the RNGestureHandler, RNReanimated, and RNScreens module it's related to react-navigation)

error Could not find the following native modules: RNAWSCognito, RNGestureHandler, RNReanimated, RNScreens. Did you forget to run "pod install" ?

so I tried and error disappeared

Detected React Native module pods for RNAWSCognito, RNGestureHandler, RNReanimated, and RNScreens
Analyzing dependencies
Downloading dependencies
Installing JKBigInteger2 (0.0.5)
Installing RNAWSCognito (3.2.1)
Installing RNGestureHandler (1.5.2)
Installing RNReanimated (1.4.0)
Installing RNScreens (2.0.0-alpha.22)
Generating Pods project
Integrating client project
Pod installation complete! There are 32 dependencies from the Podfile and 31 total pods installed.
adibas03 commented 4 years ago

Leaving this here for anyone who it might help. Following the instruction on the amazon-cognito-identity-js package readme is sufficient. https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js
I was battling this for 3 days, full disclosure, it was my error. The react-native link command did not work, because I changed the package name, and did not update the android activity folder hierarchy correctly, which is required for the linking to happen.

The error thrown when linking fails, should be more conspicuous in my opinion

thenderson55 commented 4 years ago

Installing amazon-cognito-identity-js solves the issue but does your login persist?

I get logged out on every refresh. Some other older issues mention this and the solution was to upgrade from aws-amplify v1 to v2. I am now on v3 doesn't persist.

I will probably try redux persist but it seems like amplify should automatically access asyncStorage to persist login

Jonathan0wh commented 4 years ago

This should be added to README documentation of aws-amplify, especially for the React Native part. I followed the normal README guide to install aws-amplify but also got this error before I googled it and went here. It should be emphasised that both aws-amplify and amazon-cognito-identity-js should be installed for React Native (at least for now as a workaround).

smartcris commented 3 years ago

This should be added to README documentation of aws-amplify, especially for the React Native part. I followed the normal README guide to install aws-amplify but also got this error before I googled it and went here. It should be emphasised that both aws-amplify and amazon-cognito-identity-js should be installed for React Native (at least for now as a workaround).

My yarn install log clearly show the amazon-cognito-identity-js being added when the "@aws-amplify/auth" package is installed. More than a clarification we need a fix.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.