Aws-sdk-js: aws-sdk (v 2.395.0) and react-native (v 0.58.3)

Created on 29 Jan 2019  ·  24Comments  ·  Source: aws/aws-sdk-js

Am in the throes of upgrading a react native application that I've inherited responsibilities for, and am coming across some build issues after upgrading react native.

I have decided to nuke the old project (based on RN 0.53.3) and created a new project with RN 0.58.2. After shoe horning the source in, my builds to simulator were getting hung up in the metro bundler at ~99%, with the application eventually timing out telling me that it Could not connect to development server.

Unable to effectively debug the issue, I have been going file by file, code dependency by dependency to narrow down the issue, and the first issue that is causing this hang up is actually the aws-sdk npm module.

After simply adding the import AWS from 'aws-sdk/dist/aws-sdk-react-native' statement, build demonstrates the outlined behavior.

Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(Could not connect to development server.

Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate
- WiFi is enabled and connected to the same network as the Node Server

URL: http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false The operation couldn’t be completed. (NSURLErrorDomain error -999.))

__38-[RCTCxxBridge loadSource:onProgress:]_block_invoke.226
    RCTCxxBridge.mm:412
___ZL36attemptAsynchronousLoadOfBundleAtURLP5NSURLU13block_pointerFvP18RCTLoadingProgressEU13block_pointerFvP7NSErrorP9RCTSourceE_block_invoke.118
-[RCTMultipartDataTask URLSession:streamTask:didBecomeInputStream:outputStream:]
__88-[NSURLSession delegate_streamTask:didBecomeInputStream:outputStream:completionHandler:]_block_invoke
__NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
-[NSBlockOperation main]
-[__NSOperationInternal _start:]
__NSOQSchedule_f
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_continuation_pop
_dispatch_async_redirect_invoke
_dispatch_root_queue_drain
_dispatch_worker_thread2
_pthread_wqthread
start_wqthread

RN Environment information is as follows:

  React Native Environment Info:
    System:
      OS: macOS 10.14
      CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
      Memory: 1.04 GB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 8.12.0 - /usr/local/bin/node
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 7, 8, 9
        Build Tools: 19.1.0, 21.1.2, 22.0.1, 23.0.1, 23.0.2, 25.0.2, 26.0.3, 27.0.3, 28.0.2
        System Images: android-22 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.3 => 0.58.3 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7
      react-native-patch: 0.2.0
guidance third-party

Most helpful comment

@dannyskim

I wanted a chance to review this a bit further.

I was able to build RN v0.56.1 using the latest version of the SDK. v0.57.0 and later produced heap out of memory errors.

Did running react-native bundle or Metro Bundler return heap out of memory errors for you?

Those memory errors can be worked around by running the following:
export NODE_OPTIONS="--max-old-space-size=2048”

Allocating more memory to Node allowed me to build RN v0.58.3 with the latest version of the SDK imported.

Depending on your project, you may need to bump up the memory even further.

All 24 comments

@dannyskim,

Thanks for raising this issue. We'll need to dig into this a bit further. Thanks for including these details.

@srchase seeing as how I can replicate this issue in a brand new RN project via react-native init ... and simply adding the import statement, my project is being currently held up from being updated and deployed live to app stores.

Do you or another dev member have a hard suggestion on which RN version I should utilize for the time being where this issue is not present?

@dannyskim

I wanted a chance to review this a bit further.

I was able to build RN v0.56.1 using the latest version of the SDK. v0.57.0 and later produced heap out of memory errors.

Did running react-native bundle or Metro Bundler return heap out of memory errors for you?

Those memory errors can be worked around by running the following:
export NODE_OPTIONS="--max-old-space-size=2048”

Allocating more memory to Node allowed me to build RN v0.58.3 with the latest version of the SDK imported.

Depending on your project, you may need to bump up the memory even further.

@srchase

It appears that my project exhibits the same behavior. If Metro Bundler is left alone after attempting a build, about 3 - 5 minutes after my project red screens, I see Metro spit out the following:

transform[stdout]: 
transform[stdout]: <--- Last few GCs --->
transform[stdout]: 
transform[stdout]: [88606:0x103000000]   220175 ms: Mark-sweep 1250.3 (1470.4) -> 1250.2 (1470.4) MB, 2329.9 / 0.0 ms  allocation failure GC in old space requested
transform[stdout]: [88606:0x103000000]   222217 ms: Mark-sweep 1250.2 (1470.4) -> 1250.2 (1431.4) MB, 2041.9 / 0.0 ms  last resort GC in old space requested
transform[stdout]: [88606:0x103000000]   224452 ms: Mark-sweep 1250.2 (1431.4) -> 1250.2 (1426.9) MB, 2235.4 / 0.0 ms  last resort GC in old space requested
transform[stdout]: 
transform[stdout]: 
transform[stdout]: <--- JS stacktrace --->
transform[stdout]: 
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]: 
transform[stdout]: Security context: 0x3605f07a5879 <JSObject>
transform[stdout]:     1: append [<PROJECT_PATH>/node_modules/@babel/generator/lib/buffer.js:~74] [pc=0x2755ec55b7cb](this=0x3605fdbe7071 <Buffer map = 0x360508150f91>,str=0x3605f07837e9 <String[7]: refresh>)
transform[stdout]:     2: Identifier [<PROJECT_PATH>/node_modules/@babel/generator/lib/generators/types.js:~46] [pc=0x275...
transform[stdout]: 
transform[stderr]: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
transform[stderr]:  1: node::Abort() [/usr/local/bin/node]
transform[stderr]:  2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
transform[stderr]:  3: 
transform[stderr]: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
transform[stderr]:  4: 
transform[stderr]: v8::internal::Factory::NewUninitializedFixedArray(int) [/usr/local/bin/node]
transform[stderr]:  5: 
transform[stderr]: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacity(v8::internal::Handle<v8::internal::JSObject>, unsigned int) [/usr/local/bin/node]
transform[stderr]:  6: 
transform[stderr]: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
transform[stderr]:  7: 0x2755ec4042fd
transform[stderr]:  8: 0x2755ec55b7cb

@srchase

As advised I ran export NODE_OPTIONS="--max-old-space-size=4096" (ran with 2GB and 4GB). Still exhibits similar behavior to my previous post.

After running the above command in bash, I verified by running export and made sure that my env variable was set, and it was both times.

@dannyskim

Does using an older version of the SDK make a difference? How about v2.350.0?

Did you have success building the app with RN v0.56.1?

@srchase
I've reverted to utilizing v2.318.0 with RN v0.56.1 and the errors have gone away. I will keep you updated as I am now going through the process of eliminating errors and dealing with deprecations from updating other libraries associated with the project.

I will be available to assist you in any way that I can while you are still investigating the original issue if you should so need.

I can confirm this is still happening with 2.404.0 (RN 0.58.3)

@srchase, working with @dannyskim I was able to get the project building with the lastest AWS-SDK and RN 0.58.4 running in debug locally. However when I go to produce an IPA or APK react native hangs during the bundling phases, "bundleJSandAssets" or run custom shell scripts (Bundle RN Code and Assets) respectively.

Do you know if devs using this library through AWS-Amplify are having this same issue? I did not see aws-sdk as a dependency and if switching over will get us moving faster we will do it.
Edit: dug into aws-amplify-react-native more and found the usage of aws-sdk, seems like we're stuck...

Let me know what I can provide you that could help get to the bottom of this issue.

Edit 2: @srchase our company pays for Amazon support, any suggestions on where to start raising this issue louder with that to get this as a higher ticket?

Add Max-old-space-size at react-native-xcode.sh

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

[ -z "$NODE_ARGS" ] && export NODE_ARGS="--max-old-space-size=4096"

[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/cli.js"

[ -z "$BUNDLE_COMMAND" ] && BUNDLE_COMMAND="bundle"

I am having the same issue with 0.58.6, 0.59.2 and 0.59.3 of RN.

@jacobbodkin did you raise a ticket in the (paid) AWS support center?

I am additionally experiencing this issue,

tried to set maxi-old-space-size but still the same memory issue with react native 0.59.3 and aws-sdk 2.452.0

I am facing this issue with rn-0.59.8 and asw-sdk 2.378.0.

+1

Facing this with aws-sdk 2.483.0 and react-native 0.59.9! I'm now unable to use the aws sdk in my app. Why isn't this getting more attention??

Facing this with aws-SDK 2.483.0 and react-native 0.59.9. Now I am able to run the app in the simulator, Unable to archive it.

Facing this with aws-SDK 2.483.0 and react-native 0.59.10. Now I am able to run the app in the simulator, Unable to archive it.
Please help..

Same with aws-SDK 2.502.0 and react-native 0.60.4

Just tack on another, this issue still persists on aws-sdk: 2.532.0 with react-native: 0.61.2

I fixed this memory issue in my project with below steps.
React-Native : 0.60.5
aws-sdk: 2.398.0

  • In your package.json add below line in a scripts,

"start-max": "node --max-old-space-size=8192 node_modules/react-native/local-cli/cli.js start"

  • Restart your npm with below command

npm run start-max

Closing this issue now because of inactivity, please open a new issue if this issue still persists.

Would be happy to help.

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.

Was this page helpful?
0 / 5 - 0 ratings