Global.util.crypto.lib.randomBytes is not an error function

I am new to reaction. I get the following error on error when using amazon-cognito-identity-js npm package, which reads as follows

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

My Actions file in the reaction is as follows

  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')); }) } } 

My User Authenticate service file is as follows

 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; 

My package.json file is as follows

  "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" } 

I can’t understand why I get this error? Can someone point out what I'm doing wrong?

+5
source share
1 answer

Lowering aws-sdk eliminates the problem:

 yarn add aws-sdk@2.177.0 

For me, aws-sdk is an aws-amplify dependency and is automatically updated, after which I started to see the same error.

+4
source

Source: https://habr.com/ru/post/1274585/


All Articles