Expo Go & Amplify - Uncaught Error: cannot read property 'configure' of undefined

40 Views Asked by At

When running Expo GO with a simple App.js file, I get the runtime error:

"Uncaught Error: cannot read property 'configure' of undefined"

This a new Expo GO project with the initial Amplify setup taken from this device.js from this repo in

this AWS project blog

App.js:

`import { StatusBar } from 'expo-status-bar';
import * as FileSystem from 'expo-file-system';
import { StyleSheet, Text, View } from 'react-native';
import Amplify from 'aws-amplify';
import amplifyconfig from './src/amplifyconfiguration.json';

Amplify.configure(amplifyconfig);

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
`

package.json:

`{
  "name": "locapp-10",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@aws-amplify/react-native": "^1.0.16",
    "@aws-amplify/ui-react-native": "^2.1.2",
    "@react-native-async-storage/async-storage": "^1.22.0",
    "@react-native-community/netinfo": "^11.3.0",
    "amazon-cognito-identity-js": "^6.3.7",
    "aws-amplify": "^6.0.16",
    "expo": "~50.0.7",
    "expo-status-bar": "~1.11.1",
    "react": "18.2.0",
    "react-native": "0.73.4",
    "react-native-get-random-values": "^1.9.0",
    "react-native-url-polyfill": "^2.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}`

Project setup:
$ npx create-expo-app ./scratchpad-expo-amplify

$ cd scratchpad-expo-amplify

$ amplify init

$ npm install @aws-amplify/ui-react-native aws-amplify amazon-cognito-identity-js react-native-url-polyfill

$ npm install aws-amplify @aws-amplify/react-native @react-native-community/netinfo @react-native-async-storage/async-storage [email protected]

$ npx expo start

1

There are 1 best solutions below

0
Richard Stimson On

Resolved by changing the import from:

import Amplify from 'aws-amplify';

to

import { Amplify } from 'aws-amplify';

See https://repost.aws/questions/QU-44BL-7CSYKVQbMkM7Azig/export-default-imported-as-amplify-was-not-found-in-aws-amplify