aws-sdk-js: 'JavaScript heap out of memory' when adding a dependency on the SDK to a small react-native app

Adding a dependency on the aws-sdk-js to a small react-native app causes react-native bundler to crash with ‘JavaScript heap out of memory’:

Added this line (per the README.MD) to my app.js (no other code changed):

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

Results in the following when launching my app: ┌────────────────────────────────────────────────────────────────────────────┐ │ Running Metro Bundler on port 8081. │ │ │ │ Keep Metro Bundler running while developing on any JS projects. Feel │ │ free to close this tab and run your own Metro Bundler instance if you │ │ prefer. │ │ │ │ https://github.com/facebook/react-native │ │ │ └────────────────────────────────────────────────────────────────────────────┘ Looking for JS files in D:\Proj

Metro Bundler ready.

Loading dependency graph, done. transform[stderr]: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory transform[stderr]: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory transform[stderr]: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory Bundling index.js [development, non-minified] 99.6% (556/557), failed. error: bundling failed: Error: Uncaught error in the transformer worker: D:\Proj\node_modules\metro-bundler\src\transformer.js at _transform.then.catch.error (D:\Proj\node_modules\metro-bundler\src\JSTransformer\index.js:191:31) at process._tickCallback (internal/process/next_tick.js:109:7)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

@non-standard and @AllanFly120, we were able to solve this issue. Although the symptom was a memory issue, that does not seem to be the actual root cause. It appears that the AWS file we are importing is already transpiled and can be left out when doing the babel transformation. This can be achieved by adding the following to the package.json of our react native project:

“babel”: { “ignore”: [“node_modules/aws-sdk/dist/aws-sdk-react-native.js”] },

Without the above, it seems that the packager goes into a loop and no matter how much memory you give node, it’s never enough. We got a hint that this could be the issue looking at this post. There are other ways to ignore said file, including adding the above code to the package.json of the aws-sdk itself. @AllanFly120 feel free to address it the way you deem more appropriate. At a minimum it’d be great if a note could be added to the readme for those that use the aws-sdk in a react-native project.