amplify-js: React Native Expo Auth.signIn shows error

Describe the bug When I use the function Auth.signIn it gives me error [TypeError: (0, _getRandomBase.default) is not a function. (In '(0, _getRandomBase.default)(array.byteLength)', '(0, _getRandomBase.default)' is undefined)] Only this function produces an error, Sign Up and Federated Sign In both work perfectly

To Reproduce Steps to reproduce the behavior:

Initialize an expo project by following steps on https://docs.amplify.aws/lib/auth/getting-started/q/platform/js and call the Auth.signIn command

Expected behavior I expect to sign in or an error

Code Snippet package.json

{
  "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": {
    "@eva-design/eva": "^2.0.0",
    "@react-native-community/masked-view": "0.1.10",
    "@react-native-community/netinfo": "^5.9.10",
    "@react-navigation/native": "^5.9.2",
    "@react-navigation/stack": "^5.14.2",
    "@ui-kitten/components": "^5.0.0",
    "@ui-kitten/eva-icons": "^5.0.0",
    "@ui-kitten/moment": "^5.0.0",
    "amazon-cognito-identity-js": "^4.5.10",
    "aws-amplify": "^3.3.17",
    "aws-amplify-react-native": "^4.3.1",
    "expo": "^40.0.1",
    "expo-status-bar": "~1.0.3",
    "expo-web-browser": "~8.6.0",
    "lottie-react-native": "~2.6.1",
    "moment": "^2.29.1",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
    "react-native-gesture-handler": "~1.8.0",
    "react-native-modal": "^11.6.1",
    "react-native-reanimated": "~1.13.0",
    "react-native-safe-area-context": "3.1.9",
    "react-native-screens": "^2.15.2",
    "react-native-shimmer": "^0.6.0",
    "react-native-svg": "^12.1.0",
    "react-native-web": "~0.13.12"
  },
  "devDependencies": {
    "@babel/core": "^7.9.6",
    "@babel/plugin-proposal-decorators": "^7.12.13",
    "@ui-kitten/metro-config": "^5.0.0",
    "react-native-svg-transformer": "^0.14.3"
  },
  "private": true
}

Smartphone (please complete the following information):

  • Device: [iPhone12]

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 18 (4 by maintainers)

Most upvoted comments

@mikeRChambers610 Could you also share what version of aws-amplify you are using? We just published a new version yesterday that includes the changes for this issue.

@marziamura Could you describe what issue you are seeing with expo:publish as it relates to Amplify? Also, are you using the latest version of aws-amplify?

We were also having this problem, I tried @xgallom’s solution (thanks btw 🌮 ) and it seems like a fix. Here are the steps I followed:

  • Installed @expo/metro-config as dev-depedency: npm install @expo/metro-config --save-dev
  • replaced the import statement of getDefaultConfig from metro-config to @expo/metro-config
  • passed the __dirname argument to getDefaultConfig

Here is our metro.config.js file now:

const { getDefaultConfig } = require('@expo/metro-config');

module.exports = (async () => {
    const {
        resolver: { sourceExts, assetExts }
    } = await getDefaultConfig(__dirname);
    return {
        transformer: {
            babelTransformerPath: require.resolve('react-native-svg-transformer')
        },
        resolver: {
            assetExts: assetExts.filter(ext => ext !== 'svg'),
            sourceExts: [...sourceExts, 'svg']
        }
    };
})();

@marziamura can give this a try, if you’re still getting the error.

Looks like the same issue here: https://github.com/aws-amplify/amplify-js/issues/8113

Can you try again with the EXPO_LEGACY_IMPORTS=1 environment variable?

You need to getDefaultConfig from @expo/metro-config not from metro-config.

As I mentioned above, try using const defaultConfig = require('@expo/metro-config').getDefaultConfig(__dirname); instead