Closed alyiev closed 2 months ago
Hi @fruity4pie ,
Since you are using expo and react, can you please include a github repo with the necassary steps needed to run your code and observe the error youre running into?
Thanks, Ran~
@RanVaknin just do npx create-expo-app --template
install aws-location ctrl+c -> ctrl+v the code above -> check result.
I ran into this bug and I solved it by switching to the JSC engine for iOS:
{
"expo": {
"jsEngine": "hermes",
"ios": {
"jsEngine": "jsc"
}
}
}
@phatmann this isn't solution, because hermes works faster and produces less code. I guess jsc will be deprecated in the next expo versions.
The main question how to solve it in hermes? 😄
@fruity4pie For me using Hermes is not important, and I figure there are other people in the same situation as me that just want to get the builds working again. That is why I posted the workaround. This said, I want to use Hermes if I can, so I hope someone can provide a solution!
Here is a related issue.
For reference, this is the code that react-native-get-random-values
runs:
global.ExpoModules.ExpoRandom.getRandomBase64String(10)
And here is an Expo maintainer confirming that it works in a clean Expo project:
https://github.com/expo/expo/issues/17270#issuecomment-1498774816
So something more is needed to trigger this, maybe the Hermes thing 🤔
I think that the best way to solve this would be to provide a minimum viable test case which just calls global.ExpoModules.ExpoRandom.getRandomBase64String
and submit that to the Expo team.
It is very strange.
I did clean install and was able to run aws. But in my prev setup was expo-router. Maybe it breaks smth. Gonna check tomorrow clean setup + expo-router.
Also noticed that in expo 49 expo-random will be deprecated.
For me the problem is that the segment module includes uuid.js which imports react-native-get-random-values. The segment module lists react-native-get-random-values as a peer dependency, but I had never installed it. Perhaps another module was depending on it so I did not notice. Once I added react-native-get-random-values as dependency to my project, then I get the "getRandomBase64String" error.
For me the problem is that the segment module includes uuid.js which imports react-native-get-random-values. The segment module lists react-native-get-random-values as a peer dependency, but I had never installed it. Perhaps another module was depending on it so I did not notice. Once I added react-native-get-random-values as dependency to my project, then I get the "getRandomBase64String" error.
Doing this backwards fixed the issue for me; removing the dependency from the project and letting the peer dependency handle it. I was experiencing this error through the react-native-gifted-chat library which uses uuid -> react-native-get-random-values. Oddly, I had this dependency manually added for a while and didn't see any issues until recently, but removing it has resolved the issue
If I remove the dependency, then uuid.js in the segment module fails to build. Glad it worked for you!
Yeah, If someone can capture the reproduction in which this call global.ExpoModules.ExpoRandom.getRandomBase64String(10)
fails I'd be happy to take a look.
In general though I'd suggest to use expo-crypto
as this provides new fast cryptographic functions using new Expo modules API and typed arrays without any conversion in JSland :)
There's a web polyfill as well: https://github.com/expo/expo/tree/main/packages/expo-standard-web-crypto
@LinusU Perhaps you'd be up to moving to the expo-crypto package in https://github.com/LinusU/react-native-get-random-values as well?
Based on the discussion in this thread, this doesn't seem related to the SDK. The AWS SDK cannot guarantee compatibility with all 3rd party tools such as Hermes.
Unless you can provide a minimal repo that can consistently raise this issue (ideally a project with only the absolute necessary imports) , I think that this question is more appropriate to be directed at the Expo / Hermes maintainers.
Thanks, Ran~
I 100% agree @RanVaknin. I am not even using AWS SDK, but I ran into this issue and cannot find it raised anywhere else. It is specific to my Mac dev environment, as other developers from my team don't seem to be running into it! Furthermore, it happens on iOS and Android builds.
@LinusU Perhaps you'd be up to moving to the expo-crypto package in https://github.com/LinusU/react-native-get-random-values as well?
@aleqsio Will do, would you mind reviewing this for me? https://github.com/LinusU/react-native-get-random-values/pull/45 🙏
@LinusU the fix works! Thanks so much!
The original error I got was:
"TypeError: Cannot read property 'getRandomBase64String' of undefined, js engine: hermes
ERROR Invariant Violation: "main" has not been registered. This can happen if:
Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
A module failed to load due to an error and AppRegistry.registerComponent
wasn't called., js engine: hermes"
I was running a development build from expo. I was installing segment analytics.
I ran the following two commands which fixed my problems:
Found this at: https://docs.statsig.com/client/reactNativeExpoSDK
My fix was:
npx expo install react-native-get-random-values
In src/index.js
:
import 'react-native-get-random-values';
import 'expo-router/entry';
In package.json
: "main": "src/index.js"
Since the issue is not related to the SDK, and there's a workaround posted here, I'm going to go ahead and close this.
Thanks, Ran~
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Checkboxes for prior research
Describe the bug
Using "expo": "~48.0.15".
Getting this error:
[TypeError: Cannot read property 'getRandomBase64String' of undefined] ERROR
SDK version number
@aws-sdk/client-location ^3.321.1
Which JavaScript Runtime is this issue in?
React Native
Details of the browser/Node.js/ReactNative version
node: 16.20.0
Reproduction Steps
Observed Behavior
When I'm trying to send a command, getting the error.
Connected these libs:
import 'react-native-get-random-values'; import 'react-native-url-polyfill/auto'; import 'url-polyfill';
Didn't help
Expected Behavior
Returned the location object from the service.
Possible Solution
No response
Additional Information/Context
No response