我将项目升级到本机版本0.64后,awsmplify无法正常工作。主要是,我正在尝试进行身份验证工作流,但是即使注册功能工作得很好,登录功能也会抛出“无法读取未定义的属性'computeModPow'”。
深入研究问题之后,我发现“ aws-cognito-identity-js”是主要问题。如果我尝试链接库,则捆绑程序会引发错误,表明“ 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)"
答案 0 :(得分:0)
我遇到了同样的问题,并尝试根据https://aws-amplify.github.io/docs/js/react#add-auth运行react-native link amazon-cognito-identity-js
。
然而,即使清理了构建,重新启动了打包程序等,Cannot read property 'computeModPow' of undefined
错误仍然存在。
问题在于该软件包从未与react-native link amazon-cognito-identity-js
正确链接。这需要我们手动链接,这很容易做到!
假设使用XCode(查找here来找到用于Android的类似过程),请转到Project Navigator
,然后右键单击包含所有第三方.xcodeproj的Libraries
文件夹。选择Add Files...
,然后从RNAWSCognito.xcodeproj
目录中添加${projectDir}/node_modules/amazon-cognito-identity-js/ios/
。打开RNAWSCognito.xcodeproj
和Products
文件夹,并将libRNAWSCognito.a
拖到“常规”选项卡下的Linked Frameworks and Libraries
。重新运行该项目,应该很好。可能需要清理,重新启动打包程序等。
答案 1 :(得分:0)
您可以通过以下操作解决此问题:
yarn add amazon-cognito-identity-js
react-native link amazon-cognito-identity-js
cd ios ; pod update ; cd ..
干杯!
答案 2 :(得分:0)
我不知道谁需要这个,但是在我确认了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()
);
}
祝你好运。