AWS Amplify Sign in error - Error signing in... [TypeError: (0, _getRandomBase.default) is not a function

Viewed 891

I have setup a simple React-native application that uses AWS Amplify to handle Authentication.

Sign up functionality works fine but when I try to sign-in I get this error in the console:

Error signing in... [TypeError: (0, _getRandomBase.default) is not a function. (In '(0, _getRandomBase.default)(array.byteLength)', '(0, _getRandomBase.default)' is undefined)]

I have found a similar post online for the same error but after trying every suggested fix I have decided to ask on here. Below is my package.json file.

  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "^6.0.0",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.4",
    "amazon-cognito-identity-js": "^4.6.0",
    "aws-amplify": "^3.3.27",
    "aws-amplify-react-native": "^4.3.2",
    "expo": "~41.0.1",
    "expo-status-bar": "~1.0.4",
    "joi": "^17.4.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-reanimated": "^2.1.0",
    "react-native-safe-area-context": "3.2.0",
    "react-native-screens": "~3.0.0",
    "react-native-web": "^0.16.0"
  },
  "devDependencies": {
    "@babel/core": "^7.13.16",
    "webpack-cli": "^4.6.0"
  },
  "private": true
}

It was suggested that I delete my node_modules folder and reinstall them using npm install but this has not resolved the bug. I am testing my application with Expo FYI. You will notice I have specified the react version as 39.0.02. This is because of an error when testing my application which is caused by react-native-reanimated, specifying the version fixes this other bug: https://forums.expo.io/t/error-on-launching-android-app-animated-node-with-tag-1-does-not-exist/50053.

Here is the suggested fixes I have tried - https://github.com/aws-amplify/amplify-js/issues/7191

2 Answers

In my case I have found a workaround to fix this issue. If you are using Expo please look at this link: https://github.com/aws-amplify/amplify-js/issues/8113

In here there is a fix to change the environment variables for Expo before launching it. This fixes the login/auth issues I was experiencing. I hope this helps anyone else who has the same problem.

The problem is caused by:

Expo deprecating *.expo.js filetype handling, which amazon-cognito-identity-js is using.

The environment variable you can set is EXPO_LEGACY_IMPORTS, so if you start Expo like below, it should work again:

EXPO_LEGACY_IMPORTS=1 expo start

Try updating to the latest aws-amplify. This helped me fix the issue permanently and it didnt break any of my current code.

sudo npx npm-check-updates -i '/@?aws-amplify/' && npm update --force
Related