Closed Keling-Molaris closed 1 month ago
Hello, @Keling-Molaris and sorry to hear that you're running into this. I believe this could be related to a known issue where there was a race condition potentially with Amplify.configure()
calls when using the GraphQL API library. A fix was released in v6.0.16 just last week after you opened this issue.
Can you see if upgrading to the latest version resolves the errors you're seeing? If not, we'll dig deeper to figure out what is going on. Thanks!
Hi @cwomack , Thanks for your reply. Just try to use v6.0.16 unfortunately, the issue still persist. And in the second app, I aways have the first app's config.
Hello
I am also getting the same error.
I can successfully run the app locally, and the GraphQL API works fine (local). However, after deploying it to Amplify for production, the GraphQL API seems to encounter issues.
This is my Packages
"dependencies": { "@aws-amplify/auth": "^6.0.16", "@aws-amplify/datastore": "^5.0.16", "@aws-amplify/ui-react": "^6.1.3", "@emotion/cache": "^11.9.3", "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.8.4", "@mui/lab": "^5.0.0-alpha.88", "@mui/material": "^5.14.20", "@mui/system": "^5.8.6", "@mui/utils": "^5.8.6", "@reduxjs/toolkit": "^2.0.1", "@tabler/icons": "^1.72.0", "apexcharts": "^3.35.3", "aws-amplify": "^6.0.16", "axios": "^1.6.2", "formik": "^2.2.9", "framer-motion": "^6.3.16", "material-ui-popup-state": "^4.0.1", "prop-types": "^15.8.1", "react": "^18.2.0", "react-apexcharts": "^1.4.0", "react-card-flip": "^1.2.2", "react-device-detect": "^2.2.2", "react-dom": "^18.2.0", "react-phone-input-2": "^2.15.1", "react-redux": "^8.0.2", "react-responsive-carousel": "^3.2.23", "react-router": "6.4.0", "react-router-dom": "6.4.0", "react-scripts": "^5.0.1", "react-slick": "^0.29.0", "react-toastify": "^9.1.3", "redux": "^4.2.0", "redux-thunk": "^2.4.2", "uuid": "^9.0.1", "yup": "^0.32.11" }
This is the code I did in src/app.js
@Keling-Molaris, thanks for reopening if it's still occurring. Are you also experiencing it only in prod versions/deployed apps but not locally (similar to what @DeveloperDS-123 reported above)?
We'll investigate this further and I'll place the bug label on this issue for now.
Hi @cwomack , it's still occurring, for me the issue appears to local environment and aws hosted environment.
I gonna try some older versions of amplify lib, if there is one works.
Thank you very much!
Hi @cwomack
Thanks for your reply
Still, I am facing the same issue in deployed/production only not in local.
also i am using amplify auth for login and sigup
This is my amplifyconfiguration.json
Hi @cwomack
The above error still occurring in amplify react app hosted environment not in local
Thank you very much!
It doesn't work, so downgrading to "@aws-amplify/datastore": "5.0.0", seems to work fine. Also, this problem did not occur on Windows, Mac, but on Ubuntu. I hope this will be of some help.
^ Occuring on Mac for me currently
Looks like for me it was caused by the following setup
Amplify.configure(amplifyconfig);
//Uncommenting this code causes issue
// const existingConfig = Amplify.getConfig();
// Amplify.configure({
// ...existingConfig,
// API: {
// REST: {
// [amplifyconfig.custom.apiName]: {
// endpoint: amplifyconfig.custom.apiEndpoint,
// region: amplifyconfig.custom.apiRegion,
// },
// },
// },
// });
Looks like for me it was caused by the following setup
Amplify.configure(amplifyconfig); //Uncommenting this code causes issue // const existingConfig = Amplify.getConfig(); // Amplify.configure({ // ...existingConfig, // API: { // REST: { // [amplifyconfig.custom.apiName]: { // endpoint: amplifyconfig.custom.apiEndpoint, // region: amplifyconfig.custom.apiRegion, // }, // }, // }, // });
I got the same error after adding the customized REST api.
My packages: "aws-amplify": "^6.0.23" "@aws-amplify/backend": "^0.13.0-beta.11", "@aws-amplify/backend-cli": "^0.12.0-beta.13",
Looks like for me it was caused by the following setup
Amplify.configure(amplifyconfig); //Uncommenting this code causes issue // const existingConfig = Amplify.getConfig(); // Amplify.configure({ // ...existingConfig, // API: { // REST: { // [amplifyconfig.custom.apiName]: { // endpoint: amplifyconfig.custom.apiEndpoint, // region: amplifyconfig.custom.apiRegion, // }, // }, // }, // });
I had the same issue, solved it with the following code snippet.
const existingConfig = Amplify.getConfig();
// Check if there is an existing API configuration
if (!existingConfig.API) {
Amplify.configure({
...existingConfig,
API: {
REST: {
[config.custom.apiName]: {
endpoint: config.custom.apiEndpoint,
region: config.custom.apiRegion,
},
},
},
});
} else {
// Merge the existing API configuration with the new one
Amplify.configure({
...existingConfig,
API: {
...existingConfig.API,
REST: {
...existingConfig.API.REST,
[config.custom.apiName]: {
endpoint: config.custom.apiEndpoint,
region: config.custom.apiRegion,
},
},
},
});
}
Would it be possible to update the documentation to match the updated configure call? This seems to be a common configuration for Amplify, and the documentation doesn't note this issue. (ex: https://docs.amplify.aws/nextjs/build-a-backend/add-aws-services/rest-api/set-up-rest-api/)
@matiassotose Thanks your solution solved my issue, the issue happens on a single-page react app (not in a micro-frontend context) with custom rest api config missing ...existingConfig.API
, I think it can also be simplified a bit like this:
Amplify.configure(outputs);
const existingConfig = Amplify.getConfig();
Amplify.configure({
...existingConfig,
API: {
...existingConfig.API, // fix by this line
REST: outputs.custom.API,
},
});
I also folloed this doc as mentioend by @thomasdavidwang, so I also reported it as a bug in the doc repo
Hi all, I spent some time to play with the micro frontend environment, and noticed that when there are two instances of Amplify category packages (scoped with @aws-amplify/
) I can reproduce this issue. To resolve this issue I needed to update the shared
configuration of the ModuleFederationPlugin
in my webpack.config.js
aws-amplify
package (this is the umbrella package the coordinates all Amplify category packages), you can do this by the following in the webpack.config.js
shared
configuration (ensure the same settings applied to all the codebases)// the dependencies of your project
const deps = require("./package.json").dependencies;
// the dependencies of the aws-amplify package
const amplifyDeps = require("./node_modules/aws-amplify/package.json").dependencies;
...
new ModuleFederationPlugin({
name: "mainapp",
filename: "remoteEntry.js",
remotes: {
remoteComponent: "remoteComponent@http://localhost:9001/remoteEntry.js",
},
exposes: {},
shared: {
...deps,
...amplifyDeps, // ensure the Amplify category packages are shared to avoid multiple instances
react: {
singleton: true,
requiredVersion: deps.react
},
"react-dom": {
singleton: true,
requiredVersion: deps["react-dom"]
}
}
}),
This is due to that "by default webpack will only share the root level of a library" according to the webpack documentation.
If you are using a similar set up, could you give it a try see if it resolve the issue you encountered?
Hi all, I spent some time to play with the micro frontend environment, and noticed that when there are two instances of Amplify category packages (scoped with
@aws-amplify/
) I can reproduce this issue. To resolve this issue I needed to update theshared
configuration of theModuleFederationPlugin
in mywebpack.config.js
[...] If you are using a similar set up, could you give it a try see if it resolve the issue you encountered?
Confirmed, your provided solution solved my issue with webpack remote modules in a Amplify v6 project. After adding the amplifyDeps
as described above, the remote modules are now able to pick up the existing credentials via Amplify.configure(...)
and I can successfully call Amplify API resources from there.
(Little side hint for others that face a similar issue: You also need to make sure the npm package versions for the Amplify packages are identical across main and remote applications in the in package-lock.json
files. I only had minor different versions of a few packages, but that already led to credentials not being picked up.)
Thx for your support
Thank you for the confirmation, @moellr. We'll go ahead and close this issue out on the amplify-js
repo then since we are tracking the docs update in amplify-docs
issue 7776. If there's further questions or blockers from anyone following this, please feel free to comment back.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication, GraphQL API, Storage
Amplify Version
v6
Amplify Categories
auth, storage, api
Backend
Amplify CLI
Environment information
Describe the bug
We try to call GraphQL API in two different micro front-end app, each one has an amplify backend, and we got issues like:
[Warning] [WARN] 21:04.237 GraphQLAPI resolveConfig - The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().
Error: No credentials
If we active authenticator, we have :
Auth UserPool not configured.
In our code, we called
Amplify.configure(config)
in App.ts.Expected behavior
Authentication works, and GraphQL API return data correctly.
Reproduction steps
Amplify.configure(config)
in both App.ts.in main application:
in second application:
Call GraphQL API in main Application App.ts:
Call GraphQL API in seconde Application App.ts:
Code Snippet
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response