Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withAuthenticator throwing randomBytes is not a function #224

Closed
Darkade opened this issue Feb 2, 2018 · 13 comments
Closed

withAuthenticator throwing randomBytes is not a function #224

Darkade opened this issue Feb 2, 2018 · 13 comments

Comments

@Darkade
Copy link

Darkade commented Feb 2, 2018

After updating amplify to "aws-amplify-react-native": "^0.2.0" I'm getting this error in my login screen undefined is not a function (Evaluating '_global.util.crypto.lib.randomBytes(128)')

screen shot 2018-02-02 at 3 07 49 pm

I've searched and found that this might be a amazon-cognito-identity-js version issue amazon-archives/amazon-cognito-identity-js#646 but adding the line package.json doesn't solve the issue "aws-sdk": "2.177.0"

I'm trying with a this bare-bones app, but I'm getting the same Issue

// AWS Imports
import aws_exports from './aws-exports';

// React Imports
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import Amplify from 'aws-amplify';
import { withAuthenticator } from 'aws-amplify-react-native';
Amplify.configure(aws_exports);

class App extends Component<{}> {
    render() {
        return (
            <View>
            <Text>Test</Text>
            </View>
        );
    }
}

export default withAuthenticator(App);

I'm using aws-amplify to configure as suggested to me here #109 (comment)

Any ideas what might be going on? Thanks!

@richardzcode
Copy link
Contributor

Hi @Darkade aws-amplify-react-native 0.2.0 still referencing aws-sdk higher than 2.177.0. Could you clear node_modules then reinstall aws-amplify-react-native to make sure it is on 0.2.1 and see if problem still exists.

@Darkade
Copy link
Author

Darkade commented Feb 2, 2018

Hey @richardzcode, thanks for your answer. The issue persists.

I deleted node_modules and removed the aws-amplify-react-native from package.json
Then I npm install'd everything. Finally i ran npm install aws-amplify-react-native --save

This is my package.json in case it clarifies anything.

{
  "name": "portatic",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "aws-amplify-react-native": "^0.2.1",
    "react": "16.0.0",
    "react-native": "0.51.0",
    "react-native-elements": "^0.19.0",
    "react-native-gifted-chat": "^0.3.0",
    "react-native-vector-icons": "^4.5.0",
    "react-navigation": "^1.0.0-beta.27"
  },
  "devDependencies": {
    "babel-jest": "22.0.4",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.0.4",
    "react-test-renderer": "16.0.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

@mlabieniec
Copy link
Contributor

mlabieniec commented Feb 2, 2018

@Darkade this occurs when you don't run

react-native link amazon-cognito-identity-js

did you run this command? This is needed for the randombytes function if you are not using Expo 25+. Can you verify the version of the aws-sdk-js that is in your node_modules folder?

@Darkade
Copy link
Author

Darkade commented Feb 2, 2018

Thanks. I did ran react-native link with 0.2.0 with 0.2.1 I just ran it, but the issue persists.

$ react-native link amazon-cognito-identity-js
Scanning folders for symlinks in /Users/ivan/git/portatic/client/node_modules (18ms)
rnpm-install info Android module amazon-cognito-identity-js is already linked
rnpm-install info iOS module amazon-cognito-identity-js is already linked

We do have an Expo branch, I'm going to try it there

Thanks guys

@richardzcode
Copy link
Contributor

@Darkade The issue fixed. Could you get the latest aws-amplify-react-native (0.2.2) and have a try?

Thanks!
Richard

@Darkade
Copy link
Author

Darkade commented Feb 3, 2018

Hey guys, I tried updating to aws-amplify-react-native@0.2.2and react-native@0.52.2 but I'm getting the same error.

Here's what I did. Am I missing something?

$ rm -rf node_modules android ios
$ yarn install
$ react-native eject
$ react-native link amazon-cognito-identity-js
$ react-native run-android

Also, here's my package.json

{
  "name": "portatic",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "aws-amplify-react-native": "^0.2.2",
    "react": "16.0.0",
    "react-native": "0.52.2",
    "react-native-elements": "^0.19.0",
    "react-native-gifted-chat": "^0.3.0",
    "react-native-vector-icons": "^4.5.0",
    "react-navigation": "^1.0.0-beta.27"
  },
  "devDependencies": {
    "babel-jest": "22.0.4",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.0.4",
    "react-test-renderer": "16.0.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

What's interesting to me, but maybe is not important. Is that neither the metro window, or the log-android show me the error. Only the little message in the withAuthenticator sign in screen shows it.

I really appreciate your support, guys

@richardzcode
Copy link
Contributor

@Darkade can you use npm instead of yarn? We did find that there was an issue that causing the error when using yarn. But npm had no problem.

We fixed that issue and yarn works for us now. We'll look into more, but in the mean time maybe you could try npm?

@Darkade
Copy link
Author

Darkade commented Feb 3, 2018

@richardzcode it worked! Thanks so much, Richard

@Darkade Darkade closed this as completed Feb 3, 2018
@rayhaanq
Copy link

I'm getting this same error when logging in a user

"aws-amplify": "^0.2.4",
"aws-sdk": "^2.192.0"

@mlabieniec
Copy link
Contributor

@rayhaanq in react native you have to run

react-native link amazon-cognito-identity-js

for that function.

@rayhaanq
Copy link

rayhaanq commented Feb 11, 2018

oh sorry, not using react native. Just the normal js library @mlabieniec

@mlabieniec
Copy link
Contributor

@rayhaanq Ah ok thanks. It is the same requirement for both (currently). So if you are using js/rn right now, our libraries require a pinned version of the aws-sdk to 2.177.0 since later versions dropped the crypto browserify library. We are releasing an updated cognito sdk this week that will remove this requirement, but for now if you can pin that version for aws-sdk it should solve this for you.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants