Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native JavaScript heap out of memory when import "aws-sdk/dist/aws-sdk-react-native" #2370

Closed
LuongTruong opened this issue Nov 22, 2018 · 24 comments
Labels
third-party This issue is related to third-party libraries or applications.

Comments

@LuongTruong
Copy link

Hi everyone, I know this is an old issue and many people point to this link for the answer:

JavaScript heap out of memory

However, I cannot solve the issue by following the solution.

My code work like a charm until I add this line:

const AWS = require('aws-sdk/dist/aws-sdk-react-native');

I try to add some code to my package.json and aws-sdk package.json but non of them work.

// My package.json
{
  "babel": {
    "ignore": ["node_modules/aws-sdk/dist/aws-sdk-react-native.js"]
  },
  "rnpm": {
    "assets": [
      "src/assets/fonts"
    ]
  },
  ...
}

// aws-sdk package.json
{
  "babel": {
    "ignore": ["node_modules/aws-sdk/dist/aws-sdk-react-native.js"]
  },
  "_args": [
    [
      "aws-sdk@2.361.0",
      "/Users/yumac/Projects/Yuranga/umeus-mobile/Source/umeus"
    ]
  ],
  ....
}

Please help me if you know anything about this issue. Thank you in advance!

@LuongTruong
Copy link
Author

Here is the stack-trace:

transform[stdout]:
transform[stdout]: <--- Last few GCs --->
transform[stdout]:
transform[stdout]: [10452:0x104800000]    79749 ms: Mark-sweep 1267.8 (1449.6) -> 1267.8 (1415.6) MB, 3994.2 / 0.0 ms  (average mu = 0.090, current mu = 0.000) last resort GC in old space requested
transform[stdout]: [10452:0x104800000]    83505 ms: Mark-sweep 1267.8 (1415.6) -> 1267.8 (1410.6) MB, 3755.6 / 0.0 ms  (average mu = 0.048, current mu = 0.000) 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]:     0: ExitFrame [pc: 0x3750e1f5c0f8]
transform[stdout]:     1: StubFrame [pc: 0x3750e248c015]
transform[stdout]: Security context: 0x04318491e6e1 <JSObject>
transform[stdout]:     2: DoJoin(aka DoJoin) [0x43184905e89] [native array.js:1] [bytecode=0x4315e940699 offset=212](this=0x043188e826f1 <undefined>,l=0x04318ec15a61 <JSArray[1548785]>,m=1548785,A=0x043188e828c9 <true>,w=0x043188e829f1 <String[0]: >,v=0x043188e829a1 <false>)
transform[stdout]:     3: Join(aka Join) [0x43184905ed9] [native array.js:1] [byteco...
transform[stdout]:
transform[stderr]: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
transform[stderr]:  1: 0x10003ae75 node::Abort() [/usr/local/bin/node]
transform[stderr]:  2: 0x10003b07f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
transform[stderr]:  3: 0x1001a7ae5 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
transform[stderr]:  4: 0x100572ef2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
transform[stderr]:  5: 0x10057c3f4 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
transform[stderr]:  6: 0x10054e1e4 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
transform[stderr]:  7: 0x100826c6d v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
transform[stderr]:  8: 0x3750e1f5c0f8
transform[stderr]:  9: 0x3750e248c015
transform[stderr]: 10: 0x3750e1f118d5 

@LuongTruong
Copy link
Author

Hi aws-sdk team, it is me again. I am here to give more information about the issue.

When I install the newest version of aws-sdk, this issue appear. Version of new aws-sdk: "2.361.0".
When I install the old version of aws-sdk, this issue disappear. Version of old aws-sdk: "2.356.0".

I hope this can help both of us to figure it out the issue and how to solve it.

Thank you in advance!

@srchase srchase added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Nov 26, 2018
@no-response
Copy link

no-response bot commented Dec 3, 2018

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Dec 3, 2018
@srchase srchase removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 3, 2018
@srchase srchase reopened this Dec 3, 2018
@LuongTruong
Copy link
Author

thanks @srchase for re-open this issue, do you have any suggestion for me? Currently, aws-sdk: "2.356.0" is failed to build release on Android too.

@LuongTruong
Copy link
Author

Hi @srchase , I am able to run debug by changing the package.json to:

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

In terminal run: "npm run start-max" to start the node server with 8,192 MB.
Then run your project as normal: "react-native run-android".

Enjoy!

@ricbermo
Copy link

hey @truongluong1314520 did you manage to solve this?
I added this to my babelrc and I got it working.

"ignore": [
  "node_modules/aws-sdk/dist/aws-sdk-react-native.js"
]

@srchase srchase added third-party This issue is related to third-party libraries or applications. and removed third-party labels Jan 4, 2019
@jrounsav
Copy link

Applying the ignore opens up another error for me with the latest sdk

undefined is not an object (evaluating 'global.TYPED_ARRAY_SUPPORT')

@Gregjarvez
Copy link

@jstewmon using exclude ihttps://babeljs.io/docs/en/options#ignore worked for me. See note under ignore

@jstewmon
Copy link
Contributor

jstewmon commented Feb 7, 2019

@Gregjarvez did you mean to mention me?

@Gregjarvez
Copy link

@jstewmon sorry no.
I meant @jrounsav

@LuongTruong
Copy link
Author

@ricbermo I added the same thing to babelrc too, but it is not working for me.

I am using react native version 0.57.8

@Blutude
Copy link

Blutude commented Feb 26, 2019

I am able to run my simulator only if I run that "start-max" script beforehand, but when I try to upload my app to the app store, I keep getting the out of memory error. --max-old-space-size=8192 does not fix it in this situation. It seems like when I archive my project from xcode, it does not use the node server I created with "start-max".

I also tried adding the babel "ignore" command on both my app's package.json and the aws-sdk package.json but that does not help either. Did anyone of you figure it out?

@Blutude
Copy link

Blutude commented Feb 26, 2019

I get a "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory" instead of "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory" if that changes anything.

Here is my stack-trace:

transform[stdout]: 
transform[stdout]: <--- Last few GCs --->
transform[stdout]: 
transform[stdout]: [38882:0x104800000]    34501 ms: Scavenge 1258.5 (1435.5) -> 1250.1 (1440.5) MB, 18.6 / 0.0 ms  (average mu = 0.203, current mu = 0.122) allocation failure 
transform[stdout]: [38882:0x104800000]    37155 ms: Mark-sweep 1262.1 (1440.5) -> 1246.2 (1438.0) MB, 2596.1 / 0.0 ms  (average mu = 0.144, current mu = 0.082) allocation failure scavenge might not succeed
transform[stdout]: [38882:0x104800000]    37239 ms: Scavenge 1258.1 (1438.0) -> 1249.8 (1442.0) MB, 15.3 / 0.0 ms  (average mu = 0.144, current mu = 0.082) allocation failure 
transform[stdout]: 
transform[stdout]: 
transform[stdout]: <--- JS stacktrace --->
transform[stdout]: 
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]: 
transform[stdout]:     0: ExitFrame [pc: 0x2cd5fb5cfb7d]
transform[stdout]: Security context: 0x20d93e71d921 <JSObject>
transform[stdout]:     1: /* anonymous */ [0x20d99457d7e9] [/Users/ronyazrak/Documents/McGill/Winter18/Spap/code/PROJ_SPAP_FRONT/Spap/node_modules/@babel/traverse/lib/index.js:~87] [pc=0x2cd5fbbae5ef](this=0x20d9f43e36a1 <JSFunction traverse (sfi = 0x20d959560b49)>,0x20d993337b39 <Object map = 0x20d9932a9261>,0x20d9ece4d0b1 <Object map = 0x20d9a92681e1>,0x20d936835749 <Scope m...
transform[stdout]: 
transform[stderr]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
transform[stderr]:  1: 0x100063a65 node::Abort() [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  2: 0x100064104 node::errors::TryCatchScope::~TryCatchScope() [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  3: 0x10019d9a7 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  4: 0x10019d944 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  5: 0x1005a2122 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  6: 0x1005a4653 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  7: 0x1005a0b88 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  8: 0x10059ed45 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]:  9: 0x1005ab5ec v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]: 10: 0x1005ab66f v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]: 11: 0x10057a864 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]: 12: 0x10082cd64 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node/9.6.1/bin/node]
transform[stderr]: 13: 0x2cd5fb5cfb7d 
transform[stderr]: 14: 0x2cd5fbbae5ef 
transform[stderr]: 15: 0x2cd5fbb2ef9a 
transform[stderr]: 16: 0x2cd5fbbae453

@ricbermo
Copy link

@Blutude I'm using this version: 2.228.1, also can u try this?
open node_modules/aws-sdk/dist/aws-sdk-react-native.js.
Look for TYPED_ARRAY_SUPPORT. Replace this

Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
	  ? global.TYPED_ARRAY_SUPPORT
	  : typedArraySupport()

with this:
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()

@ricbermo
Copy link

@truongluong1314520 sorry for the late reply. can u try that ^^ as well?

@Blutude
Copy link

Blutude commented Feb 27, 2019

@ricbermo With this change, running the ios simulator works without needing to run the start-max script before hand. But Xcode --> Archive does not work, I get "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory".

If I comment out const AWS = require('aws-sdk/dist/aws-sdk-react-native');
Then Xcode --> Archive works with no problem.

@artechventure
Copy link

@Blutude
I am facing this issue with rn-0.59.8 and asw-sdk 2.378.0.
Any solutions since then?

@LuongTruong
Copy link
Author

LuongTruong commented May 28, 2019

Hi @Blutude , it took me a while to figure out how to build release. My previous comment is only for build debug, so it will not work on release version.

I wrote a post for this issue.

React native max-old-space-size

Please let me know if you still have the issue

@mikeRChambers610
Copy link

hey @truongluong1314520 did you manage to solve this?
I added this to my babelrc and I got it working.

"ignore": [
  "node_modules/aws-sdk/dist/aws-sdk-react-native.js"
]

Where is the babelrc located?

@LuongTruong
Copy link
Author

Hi @mikeRChambers610 , if you are using the latest react-native, the .babelrc file now is babel.config.js

@prurph
Copy link

prurph commented Aug 14, 2019

Adding the ignore alone was not sufficient for me using react native through expo. I also had to prepend NODE_OPTIONS=--max_old_space_size=4096 to expo start to fix the issue.

@mikechambers610
Copy link

I am surprised to say that I have looped back around to this issue.

I am using expo SDK 31 + import AWS from 'aws-sdk/dist/aws-sdk-react-native';

Unable to try a few of these fixes since Im using expo. If I comment out the import my app runs fine. Otherwise, I am getting the heap allocation failure.

Thanks!

Mike

@mikechambers610
Copy link

Adding the ignore alone was not sufficient for me using react native through expo. I also had to prepend NODE_OPTIONS=--max_old_space_size=4096 to expo start to fix the issue.

I tried this a bunch of times and it wouldnt work. After messing with a few other things and coming back to this simple fix, Im back up and running. Thank you!

@lock
Copy link

lock bot commented Sep 28, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
third-party This issue is related to third-party libraries or applications.
Projects
None yet
Development

No branches or pull requests