错误 "URL.hostname is not implemented",React Native 中的 AWS SNS Android

Error "URL.hostname is not implemented", AWS SNS in React Native Android

在 React NativeJavaScript v3 中使用来自 AWS SDK 的 SNS 服务

当我尝试创建端点(或通过 AWS 执行任何命令)时出现此错误 URL.hostname is not implemented

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

const region = 'us-west-2'
const sns = new SNSClient({
    region: region,
    credentials: fromCognitoIdentityPool({
        client: new CognitoIdentityClient({ region }),
        identityPoolId: identityPoolId,
    }) /// doesn't matter whether I pass credentials or not, same result
});

const params = {
    PlatformApplicationArn: platformApplicationArn,
    Token: token
}

const command = new CreatePlatformEndpointCommand(params);  

const res = await sns.send(command)
.catch((err) => {
    console.log(err) //// this is the "[Error: not implemented]"
    throw err 
})

这是说我应该在此错误中包含更多数据,但此错误中唯一的内容是消息。 https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sns/index.html#troubleshooting

似乎这甚至不是 AWS 错误...但我不知道如何进一步排除故障。

如有任何关于如何确定其来源的建议,我们将不胜感激。谢谢大家

找到了一些针对类似错误提出此建议的帖子:react-native-url-polyfill

添加后我开始收到此错误: [Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported]

为了解决这个问题我添加了react-native-get-random-values

... 它有效。我不确定我是否理解原因或根本原因是什么,这似乎是一个混乱的解决方法。但它确实有效。

import 'react-native-url-polyfill/auto';
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
//at the top of the file where I'm handling AWS SNS 

如果外面有人能阐明这里发生的事情,毫无疑问有更好的方法。