开发者问题收集

无法读取未定义的属性“computeModPow”

2019-07-27
1233

将我的项目升级到 react-native 0.64 后,aws amplify 无法正常工作。主要是,我试图创建一个身份验证工作流,但登录功能抛出了“无法读取未定义的属性‘computeModPow’”,即使注册功能完全正常工作。

深入研究问题后,我发现“aws-cognito-identity-js”是主要问题。如果我尝试链接库,rn bundler 会抛出一个错误,提示“aws-cognito-identity-js”已链接,或者我无法覆盖它。

有什么建议吗?

Package.json

"react": "16.8.6",
"react-native": "0.60.4",
"aws-amplify": "^1.1.32",
"aws-amplify-react-native": "^2.1.15",

实施:

export const loginUser = (credentials: any) => async (dispatch: any) => {
  dispatch({ type: LOGIN_USER });

  try {
    const data = await Auth.signIn(credentials.email, credentials.password);
    return loginUserSuccess(dispatch, data);
  } catch (error) {
    return loginUserFail(dispatch, error);
  }
};

const loginUserSuccess = (dispatch: any, data: any) => {
  console.log({ data });
  dispatch({ type: LOGIN_USER_SUCCESS, attributes: {} });
};

const loginUserFail = (dispatch: any, error: any) => {
  console.log({ error });
  dispatch({ type: LOGIN_USER_FAILED });
};

错误:

"TypeError: Cannot read property 'computeModPow' of undefined
    at BigInteger.nativeModPow [as modPow] (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:217690:17)
    at AuthenticationHelper.calculateA (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:217990:16)
    at AuthenticationHelper.getLargeAValue (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:217928:16)
    at new AuthenticationHelper (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:217910:12)
    at CognitoUser.authenticateUserDefaultAuth (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:219720:36)
    at CognitoUser.authenticateUser (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:219710:23)
    at blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:185525:14
    at tryCallTwo (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:24791:7)
    at doResolve (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:24955:15)
    at new Promise (blob:file:///6e426a68-ddf4-48ca-86cf-ba3536cb9a13:24814:5)"
3个回答

我遇到了同样的问题并尝试根据 https://aws-amplify.github.io/docs/js/react#add-auth 运行 react-native link amazon-cognito-identity-js

但是,即使在清理构建、重新启动打包程序等之后, 无法读取未定义的属性“computeModPow” 错误仍然存​​在。

问题是该包从未与 react-native link amazon-cognito-identity-js 正确链接。这需要我们手动链接,幸运的是,这很容易做到!

假设 XCode(查看 此处 了解如何对 Android 执行类似的过程)您转到 项目导航器 并右键单击包含所有第三方 .xcodeproj 的 Libraries 文件夹。选择 添加文件... 并从 ${projectDir}/node_modules/amazon-cognito-identity-js/ios/ 目录中添加 RNAWSCognito.xcodeproj 。打开 RNAWSCognito.xcodeprojProducts 文件夹,并将 libRNAWSCognito.a 拖到 General 选项卡下的 Linked Frameworks and Libraries 。重新运行项目,一切就绪。可能需要清理、重新启动打包程序等。

Image showing XCode Project Navigator with correct linking

ChrisF582
2019-08-17

您可以通过执行以下操作来解决此问题:

yarn add amazon-cognito-identity-js
react-native link amazon-cognito-identity-js
cd ios ; pod update ; cd ..

干杯!

Francois Nadeau
2019-09-24

我不知道谁需要这个,但在我确认 amazon-cognito-identity-js 之后: 1) 在 settings.gradle 中 2) 在 app/build.gradle 中

我必须确保在 MainApplication.java

import com.amazonaws.RNAWSCognitoPackage;

    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
                // eg. new VectorIconsPackage()
                new NetInfoPackage(),
                new AsyncStoragePackage(),
                new RNAWSCognitoPackage()
        );
    }

祝你好运。

OTAmpah
2020-06-12