-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem in [email protected] with [email protected] and [email protected] #14147
Comments
Hello, @tsapasMi33 and thanks for opening this issue. It looks like you have a duplicate dependency for |
Hi @cwomack and thank you for your help. I added the dep while trying to find a solution to the issue. removing it does not solve the issue. I have set up a project where the problem is reproduced: In case that helps, I have also opened an issue with the Native Federation Team here: angular-architects/module-federation-plugin#734. Let me also add to this point that we have set up a project with Module Federation and the library seems to be working out of the box. Let me know if i can provide more info. Thanks! |
@tsapasMi33, thank you for linking the associated issues and providing a sample repo! I haven't personally used Native Federation so I'll look into this a follow up after trying to reproduce this locally. |
Hi @cwomack, Just letting you know that a solution was proposed by Manfred Steyer (Native Federation). you can check out this thread: angular-architects/module-federation-plugin#734 In short, we have to import Amplify from the internal package (@aws-amplify/core) to get it to work correctly as an issue is caused with the internally shared singleton. We are still getting some warnings on the browser regarding the hub (No direct interaction on our part). Would be great to have it to work out of the box though as is the case with module federation. In case any news come up please give me a heads up. Thank you!! |
Hi @tsapasMi33 I read the thread you linked above, the suggested shared transient dependency settings makes sense to me, as the singleton that resides in However, a quick note that the For the warning specifically, it should be the same cause that multiple instances of an internal symbol were created. |
Hi @HuiSF and thank you for the response. Originally we were importing everything from aws-amplify. Except certain types. Not sure if that matters I just tried a setup with [email protected] and @angular-architects/[email protected] and I can verify that it works with this import Hope this gives some more info. Please let me know if I can provide any more information. Thank you! |
@tsapasMi33, importing things explicitly from the We'll close this issue on our repo down, but can reopen it if the linked issue #734 on Native Federation's side has more needed from us. |
Hi, I have analyzed this case. The issue for Native Federation is that the symbol ADD_OAUTH_LISTENER is imported using two different paths. This is not an issue when everything is compiled together because the bundler finds out that the same symbol is meant. However, Federation compiles each entry point separately to be loaded via an Import Map later. In this case, this results in two different Symbols. The solution for this would be change one import in import { ADD_OAUTH_LISTENER } from '@aws-amplify/core/internals/utils'; This import is in general more accurate IMHO because according to the Also, I made sure that Do you think you can add these modifications to support compilation modes using externals loaded via Import Maps? Best wishes, |
Hi, we're also experiencing this issue. We have a reproduction available if that would be helpful - https://github.com/HYuanAi/native-federation-amplify. While using the library with native-federation, multiple instances seem to be instantiated and hence no operations could be done since it complains that no configurations has been done (when it has been on another instance). For your information, we are only using the library for auth purposes, without am Amplify backend - https://docs.amplify.aws/angular/build-a-backend/auth/use-existing-cognito-resources/#use-auth-resources-without-an-amplify-backend |
Hi again @cwomack, |
Before opening, please confirm:
JavaScript Framework
Angular
Amplify APIs
GraphQL API, REST API, Authentication
Amplify Version
v6
Amplify Categories
No response
Backend
Other
Environment information
Describe the bug
We are trying to set up a project with angular 19.1.1 and [email protected].
The set up works fine in classic Angular style.
After installing Native Federation and running the schematics the app builds (certain packages need to be skipped in federation.config.js to do so)
The following errors show up in the browser and the app does not start.
As I am not sure if this is a Native federation or Amplify problem a duplicate issue has been posted to the native federation team.
For reference package.json and federation.config.js will be appended at the end of the issue.
Different configurations have given other messages. Our suspicis is that the Amplify singleton is not correctly shared between other classes that need it.
Certain error messages were about making a call before calling Amplify.configure() which was not the case as we could always recover the config via Amplify.getConfig() before the calls in question and it was present,
Expected behavior
Work out-of-the-box as in microfront-end example in https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/create-amplify-micro-frontend-portal.html (Module Federation used in example)
Reproduction steps
Code Snippet
// Put your code below this line.
Log output
aws-exports.js
No response
Manual configuration
function amplifyInitializer(): void {
Amplify.configure(
{
API: {
GraphQL: {
endpoint: getEndpoint(),
region: 'eu-west-3',
defaultAuthMode: 'oidc',
},
REST: {
api: {
endpoint: 'https://**********.execute-api.eu-west-3.amazonaws.com/v1',
region: 'eu-west-3',
},
},
},
},
{
API: {
GraphQL: {
headers: async () => {
return {
Authorization: 'Bearer ' + sessionStorage.getItem('access_token'),
host: 'fpl3kbwtxzdklbivpdsmk6uuru.appsync-api.eu-west-3.amazonaws.com',
};
},
},
REST: {
headers: async () => {
return {
'X-Api-Key': '*******kC1j',
Authorization: 'Bearer ' + sessionStorage.getItem('access_token'),
};
},
},
},
Auth: {
tokenProvider: new CustomTokenProvider(),
},
}
);
}
class CustomTokenProvider implements TokenProvider {
async getTokens(): Promise<AuthTokens | null> {
const accessToken = sessionStorage.getItem('access_token');
if (!accessToken) {
return null;
}
}
private decodeJWT(token: string): Record<string, string> {
try {
const payload = token.split('.')[1];
return JSON.parse(atob(payload));
} catch (e) {
console.error(e);
return {};
}
}
}
function getEndpoint() {
return
https://cloudfront.***********.com/graphql?header=${btoa( JSON.stringify({ host: 'fpl3***************.appsync-api.eu-west-3.amazonaws.com', Authorization: 'Bearer ' + (sessionStorage.getItem('access_token') ?? ''), }) )}&payload=e30=
;}
this method is called inside a a provideAppInitializer in app.config.ts
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
The text was updated successfully, but these errors were encountered: