aws-sdk-js-v3: [TypeError: Cannot read property 'getRandomBase64String' of undefined] ERROR
Checkboxes for prior research
- #4681
- I’ve checked AWS Forums and StackOverflow.
- I’ve searched for previous similar issues and didn’t find any solution.
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
const locationClient = new LocationClient({
credentials,
region: 'ap-south-1',
});
const params = {
IndexName: 'placesAPI',
Position: [-122.33, 47.6],
};
const command = new SearchPlaceIndexForPositionCommand(params);
const data = await locationClient.send(command);
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
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 18 (2 by maintainers)
For reference, this is the code that
react-native-get-random-values
runs: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.My fix was:
npx expo install react-native-get-random-values
In
src/index.js
:In
package.json
:"main": "src/index.js"
@LinusU the fix works! Thanks so much!
@aleqsio Will do, would you mind reviewing this for me? https://github.com/LinusU/react-native-get-random-values/pull/45 🙏
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
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.