nx-labs icon indicating copy to clipboard operation
nx-labs copied to clipboard

NX Expo not working with aws-amplify (Error: secure crypto unusable, insecure Math.random not allowed)

Open gelfer opened this issue 2 years ago • 5 comments

Current Behavior

I set up a new workspace and installed an Expo app using:

yarn add @nrwl/expo -D nx generate @nrwl/expo:app mobile

Following the aws-amplify installation guideline for Expo https://docs.amplify.aws/start/getting-started/setup/q/integration/react-native/#create-a-new-react-native-app, I installed the followings:

yarn add aws-amplify aws-amplify-react-native amazon-cognito-identity-js @react-native-community/netinfo @react-native-async-storage/async-storage @react-native-picker/picker

In App.tsx, I imported aws-amplify and logged out something from the package just to see if anything came out.

import { Auth } from "aws-amplify"

console.log(Auth)

then, npx nx start mobile.

It'd crash the app and throw out an error saying Error: secure crypto unusable, insecure Math.random not allowed.

This happened to both Android and iOS.

However, when I removed those two lines from App.tsx, things worked fine.

Expected Behavior

In a normal Expo project, that'll print out the Auth class with userPool, user, and other properties as null.

I tested by creating another project using npx create-expo-app expo-mobile and followed the installation guideline for aws-amplify.

gelfer avatar Jul 21 '22 03:07 gelfer

Can also confirm this behaviour.

@gelfer, were you able to solve this issue?

Diogo-V avatar Jul 27 '22 21:07 Diogo-V

Unfortunately, no. But it works when you turn the debugger on. On your simulator, control + command + z and then press "debug remote JS" For some reason, aws-amplify works when the Chrome debugger is running in the background, but this is not the ideal solution. I want it to work with or without the debugger 🫤

gelfer avatar Jul 28 '22 02:07 gelfer

is this because there is somewhere in the node_module files that uses Math.random() function?

xiongemi avatar Aug 05 '22 17:08 xiongemi

If I run:

npx expo-cli doctor --fix-dependencies

then I can run the project with aws-amplify without issue.

hkhamm avatar Aug 31 '22 21:08 hkhamm

Unfortunately, no. But it works when you turn the debugger on. On your simulator, control + command + z and then press "debug remote JS" For some reason, aws-amplify works when the Chrome debugger is running in the background, but this is not the ideal solution. I want it to work with or without the debugger 🫤

Did you find a way to fix this?

duyta7598 avatar Sep 11 '23 12:09 duyta7598