skip to Main Content

I’m currently developing a React Native application from scratch with Expo CLI.

I set the backend with AWS Amplify. Deploy and pull are done and everything in place.
I have the amplify folder in the project root. I have aws-export.js in ./src folder.
Necessary libraries are installed as well.

So everything is ready to connect my React Native project to backend with AWS Amplify.

According to the documentation , I imported Amplify and config.

But after I placed this line Amplify.configure(config); I’ve got this error in the terminal: TypeError: undefined is not an object (evaluating ‘_awsAmplify.default.configure’)

So this happens when put this line of code:

Amplify.configure(config);

If I comment out this line, everything is okay.

The App.js is very simple:

import { View, Text } from "react-native";

import Amplify from "aws-amplify";
import config from "./src/aws-exports";

Amplify.configure(config);

const App = () => {
  return (
    <View>
      <Text>Hello World</Text>
    </View>
  );
};

export default App;

I think there is some incompatibilty between the dependencies.

Here is my package.json:

{
  "name": "authentication",
  "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/cli": "^10.4.1",
    "@react-native-async-storage/async-storage": "^1.17.11",
    "@react-native-community/netinfo": "9.3.5",
    "@react-navigation/native": "^6.0.13",
    "@react-navigation/native-stack": "^6.9.1",
    "amazon-cognito-identity-js": "^6.0.1",
    "aws-amplify": "^5.0.1",
    "expo": "~47.0.3",
    "expo-status-bar": "~1.4.2",
    "react": "18.1.0",
    "react-hook-form": "^7.39.3",
    "react-native": "0.70.5",
    "react-native-safe-area-context": "4.4.1",
    "react-native-screens": "~3.18.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

Anyways there is another project, that doesn’t produce this error. Of course the version numbers are a bit different in the package.json as you can see:

Older project’s package.json:

"dependencies": {
    "@aws-amplify/cli": "^10.4.0",
    "@react-native-async-storage/async-storage": "^1.17.10",
    "@react-native-community/netinfo": "9.3.0",
    "@react-native-picker/picker": "2.4.2",
    "amazon-cognito-identity-js": "^5.2.12",
    "aws-amplify": "^4.3.43",
    "aws-amplify-react-native": "^6.0.8",
    "expo": "~46.0.16",
    "expo-status-bar": "~1.4.0",
    "react": "18.0.0",
    "react-native": "0.69.6",
    "react-native-gesture-handler": "~2.5.0",
    "react-native-reanimated": "~2.9.1"
  }, 

At this moment I’m working with the newest versions of the libraries. And I would like to avoid package downgrades as much as possible.

Can someone help me in this?

Thank you in advance!

2

Answers


  1. Chosen as BEST ANSWER

    Finally I found the solution.

    I used this: import Amplify from "aws-amplify";

    But Expo documentation suggests @aws-amplify/core instead of library aws-amplify.

    So the correct import looks like this: import Amplify from "@aws-amplify/core";

    And this solved my problem.


  2. It is because of a version difference. Remove previous aws-amplify and add [email protected]

    yarn remove aws-amplify && yarn add [email protected]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search