Open warrenronsiek opened 2 months ago
Hi @warrenronsiek - thanks for reaching out, sharing feedback and workarounds.
I've tried to reproduce it and can confirm that some of the steps that you mentioned around dependencies are missing from our documentation. Feedback like this are crucial as we're always looking to improve our docs to be more clear, concise and accurate. I'll work on adding the missing pieces to our docs.
Thanks again, John
@aBurmeseDev thank you for your response! The documentation updates would help greatly. I also understand that react-native-windows compatibility is a niche issue and AWS might not be inclined to fix it. That said, this still leaves the bundle resolution issue, which is breaking and is not just a documentation update. Do you have an assessment on whether or not that will be fixed?
Checkboxes for prior research
Describe the bug
When calling cognito operations (and a variety of others), the aws-sdk has a series of dependencies that are undocumented and not included in the base package.
This is closely related to https://github.com/aws/aws-sdk-js-v3/issues/4877, https://github.com/aws/aws-sdk-js-v3/issues/5736, and https://github.com/aws/aws-sdk-js-v3/issues/6013. However the workarounds suggested https://github.com/aws/aws-sdk-js-v3/issues/4877#issuecomment-1656007484, https://github.com/aws/aws-sdk-js-v3/issues/4877#issuecomment-1803353706, and https://github.com/aws/aws-sdk-js-v3/issues/6013#issuecomment-2067866695 are only part of the problem. I would expect the AWS SDK to work "out of the box" and not have to do a variety of tricks with my JS bundler, dependency hacks, and installing unlisted dependencies.
SDK version number
3.567.0
Which JavaScript Runtime is this issue in?
React Native
Details of the browser/Node.js/ReactNative version
0.74.0
Reproduction Steps
With these functions defined, the following should fail inside of a RN application:
Note that this should work fine in e.g. a Jest testing environment. It just doesn't run in RN. This suggests a bundling/dependency issue.
Observed Behavior
Initially you cycle through a series of failures discussed in https://github.com/aws/aws-sdk-js-v3/issues/4877#issuecomment-1656007484. At the end, you get to
Failed to construct URL with https://cognito-idp.us-west-2.amazonaws.com [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[0], "punycode").ucs2.decode')]
The first element in the stack refers toURLStateMachine
which is inwhatwg-url-without-unicode/lib/url-state-machine.js
package which has arequire("punycode")
at the top, which seems like our culprit.To bypass this, I hacked my node_modules/whatwg-url-without-unicode/node_modules/punycode/package.json such that the line
"module": "punycode.es6.js"
instead points topunycode.js
. (In principle, this should be fixed by https://github.com/aws/aws-sdk-js-v3/issues/4877#issuecomment-1803353706, but for some black magic reason is not.)Once I do this, I now get
"Native module not found", "name": "Error", "stack": "getRandomBase64..."
which I solved bynpx pod-install
(the documentation https://github.com/aws/aws-sdk-js-v3 says that they have to be imported, but doesn't mention needing to install pods or linking). Also,react-native-get-random-values
does not have any bindings for windows, only android/ios. Turns out ios bindings work for macos, but android isn't sufficent. Hence, this is breaking if someone is using react-native-windows.Now I get
"Can't find variable: ReadableStream", "name": "ReferenceError", "stack": "isStreamingPayload"
which seems to be the issue mentioned in https://github.com/aws/aws-sdk-js-v3/issues/5736. I solve this via stackoverflow and importing as follows:Finally, you get
Can't find variable: TextDecoder
as mentioned in https://github.com/aws/aws-sdk-js-v3/issues/4877#issuecomment-1803353706. Which is solved by adding the text-encoder-polyfill andimport 'text-encoding-polyfill';
.Expected Behavior
AWS SDK should "just work" or be very close to it. This would imply the following:
web-streams-polyfill
andtext-encoder-polyfill
or at least mention these things as independent react-native requirements in the same spot it mentionsreact-native-get-random-values
in getting started.react-native-get-random-values
.Possible Solution
No response
Additional Information/Context
No response