Skip to content
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

[React Native] Problem with parseUrl in @aws-sdk/url-parser-node #1900

Closed
ghost opened this issue Jan 12, 2021 · 3 comments
Closed

[React Native] Problem with parseUrl in @aws-sdk/url-parser-node #1900

ghost opened this issue Jan 12, 2021 · 3 comments
Assignees
Labels
duplicate This issue is a duplicate. feature-request New feature or enhancement. May require GitHub community feedback.

Comments

@ghost
Copy link

ghost commented Jan 12, 2021

I'm using @aws-sdk/client-cognito-identity and @aws-sdk/credential-provider-cognito-identity to retrieve credentials from a Cognito Identity Pool to access AWS recourses from a React Native app.

The relevant code is:

import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity";
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity";

const cognitoIdentityClient = new CognitoIdentityClient({
  region: AWS_REGION,
});
const credentials = fromCognitoIdentityPool({
  client: cognitoIdentityClient,
  identityPoolId: AWS_IDENTITY_POOL_ID,
  logins: {
    "appleid.apple.com": userToken,
  },
});

Upon resolving the promise returned by fromCognitoIdentityPool, an error is thrown:

[Unhandled promise rejection: Error: not implemented]
- node_modules/react-native/Libraries/Blob/URL.js:169:10 in get__hostname
- node_modules/@aws-sdk/url-parser-node/dist/cjs/index.js:5:26 in parseUrl
- node_modules/@aws-sdk/config-resolver/dist/cjs/EndpointsConfig.js:26:30 in getEndPointFromRegion

This seems to be cause by the line

const { hostname = "localhost", pathname = "/", port, protocol = "https:", search } = new URL(url);

The problem is that React Native contains a homemade polyfill for URL (see also facebook/react-native#16434).

As a workaround, https://github.com/charpeni/react-native-url-polyfill can be used. If I include import "react-native-url-polyfill/auto"; in the file where the fromCognitoIdentityPool() function is located, it works. I think it would be good to solve this for React Native in @aws-sdk/url-parser-node, so that people don't need to deploy their own workarounds. I'd be happy to do pull request if pointed in the right direction, but right now I'm not sure how to solve this. I guess you probably don't want to include https://github.com/charpeni/react-native-url-polyfill in @aws-sdk/url-parser-node.

@ghost ghost added the feature-request New feature or enhancement. May require GitHub community feedback. label Jan 12, 2021
@ghost ghost changed the title [React Native] Prolem with parseUrl in @aws-sdk/url-parser-node [React Native] Problem with parseUrl in @aws-sdk/url-parser-node Jan 12, 2021
@AllanZhengYP AllanZhengYP self-assigned this Jan 12, 2021
@AllanZhengYP
Copy link
Contributor

@bndkt
Thank you for reporting this! This is a regression introduced in #1766. We actually already have a ticket tracking fixing this issue: #1867. I will close this one because of duplication. Can you comment on #1867 for further discussion?

@AllanZhengYP AllanZhengYP added the duplicate This issue is a duplicate. label Jan 12, 2021
@ghost
Copy link
Author

ghost commented Jan 12, 2021

Thanks @AllanZhengYP! I actually saw #1867 but thought it must be something else, but a regression makes sense. I'll track #1867 and comment there in case I can add something.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue is a duplicate. feature-request New feature or enhancement. May require GitHub community feedback.
Projects
None yet
Development

No branches or pull requests

1 participant