I’m trying to add existing backend to a new react frontend. Every time I call the API from react i get, Uncaught (in promise) API api3ceaf69c does not exist
Client side code
JavaScript
x
15
15
1
function getData() {
2
const apiName = "api3ceaf69c";
3
const path = "/users";
4
const myInit = {
5
6
headers: {},
7
};
8
return API.get(apiName, path, myInit);
9
}
10
11
(async function () {
12
const response = await getData();
13
console.log(JSON.stringify(response));
14
})();
15
index.js
JavaScript
1
5
1
import { Amplify, API } from "aws-amplify";
2
import awsExports from "./aws-exports";
3
Amplify.configure(awsExports);
4
API.configure(awsExports);
5
aws-exports.json
JavaScript
1
10
10
1
{
2
"aws_cloud_logic_custom": [
3
{
4
"name": "api3ceaf69c",
5
"endpoint": "https://xxxxxxx.execute-api.ap-south-1.amazonaws.com/dev",
6
"region": "ap-south-1"
7
}
8
]
9
}
10
“aws-amplify”: “^4.3.27”
Error Error screenshot
I went through multiple answers around the same issue but none of them are working for me.
Interestingly this exact same code was working a few days back until I had to rebuild my backend due to some changes.
Advertisement
Answer
I figured out the problem finally! Issue was at the place where I’m calling Amplify.configure(aws_exports)
.
For some reason aws exports was not getting initialized in index.js file so I moved it closer to where I am actually calling the api, i.e. getData() function. It started working post that.