nx-labs
nx-labs copied to clipboard
NX Expo not working with aws-amplify (Error: secure crypto unusable, insecure Math.random not allowed)
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.
Can also confirm this behaviour.
@gelfer, were you able to solve this issue?
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 🫤
is this because there is somewhere in the node_module files that uses Math.random() function?
If I run:
npx expo-cli doctor --fix-dependencies
then I can run the project with aws-amplify
without issue.
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?