gpt4 book ai didi

node.js - global.util.crypto.lib.randomBytes 不是函数错误

转载 作者:搜寻专家 更新时间:2023-10-31 22:44:31 37 4
gpt4 key购买 nike

我是新手。使用 amazon-cognito-identity-js 时出错时出现以下错误npm 包如下所示

_global.util.crypto.lib.randomBytes is not a function

我在react中的Actions文件如下

    import axios from 'axios';
import * as actionTypes from './actionTypes';
import authenticateUser from '../services/cognitoAuthenticateUser';
import {reset} from 'redux-form';


const signInUserSuccess = ({...result,email, newPasswordRequired = false}) => {
return {
type: actionTypes.SIGNIN_SUCCESS,
...result,
email
}
};

const signInUserFailure = (error) => {
return {
type: actionTypes.SIGNIN_FAILURE,
error
}
};


/* Login a given user based on his credentials added */
export function LoginFeature(email,password,callback){

return (dispatch) => {
authenticateUser(email, password)
.then(result => {
//console.log(result);
dispatch(signInUserSuccess({...result, email}));
callback();
dispatch(reset('loginForm'));
})
.catch(e => {
dispatch(signInUserFailure(e.message));
dispatch(reset('loginForm'));
})
}
}

我的User Authenticate service文件如下

import {
AuthenticationDetails,
CognitoUserPool,
CognitoUser} from "amazon-cognito-identity-js";

import {Config} from "aws-sdk";


import awsConfig from "../../configs/aws-incognito-credentials";

/*Credentails for AWS Incognito usage*/
Config.region = awsConfig.region;

const userPool = new CognitoUserPool({
UserPoolId: awsConfig.UserPoolId,
ClientId: awsConfig.ClientId
});

// Use case 4. Authenticating a user and establishing a user session with the Amazon Cognito Identity service.
export const authenticateTheGivenUser = (username, password) => {
return new Promise(function (resolve, reject) {

const user = new CognitoUser({ Username: username, Pool: userPool })
const authenticationData = { Username: username, Password: password }
const authenticationDetails = new AuthenticationDetails(authenticationData)

user.authenticateUser(authenticationDetails, {
onSuccess: result => {
console.log(result);
resolve({...result, newPasswordRequired: false})
},
onFailure: err => reject(err),
newPasswordRequired: (userAttributes, requiredAttributes) => resolve({newPasswordRequired: true})
})
})
}

export default authenticateTheGivenUser;

我的package.json文件如下

 "devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"jquery": "^2.2.1",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0",
"babel-preset-stage-1": "^6.24.1",
"json-loader": "^0.5.7"
},
"dependencies": {
"amazon-cognito-identity-js": "^1.5.0",
"axios": "^0.17.1",
"babel-preset-stage-1": "^6.1.18",
"material-ui": "^0.20.0",
"material-ui-datatables": "^0.18.2",
"material-ui-icons": "^1.0.0-beta.17",
"mui-data-table": "^0.1.5",
"prop-types": "^15.6.0",
"random-bytes": "^1.0.0",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-materialize": "^1.1.2",
"react-redux": "4.3.0",
"react-router": "^2.0.1",
"react-router-dom": "^4.0.0",
"react-toastify": "^3.2.1",
"redux": "^3.0.4",
"redux-form": "^7.2.0",
"redux-thunk": "^2.2.0"
}

我无法理解为什么会出现此错误?有人可以指出我做错了什么吗?

最佳答案

降级 aws-sdk 解决了这个问题:

yarn add aws-sdk@2.177.0

对我来说,aws-sdk 是 aws-amplify 的依赖项,并且会自动更新,之后我开始看到同样的错误。

关于node.js - global.util.crypto.lib.randomBytes 不是函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48160979/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com