Search code examples
javascriptreactjsmemoryheap-memoryallocation

React - Import big JSON file - Memory Error HEAP


Error: "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory" error

I have a working react app with a relatively small footprint. However I want to import a JSON file in my React-App with lots of data. The file size is 80MB.

I import the file using: import MYJSON from './myfile.json'

What I've tested is increasing my memory for the react app to 12GB.

"node --max-old-space-size=12000 node_modules/.bin/react-scripts start"

How can it be that an 80MB file raise the memory footprint of node from under 4GB to over 12GB with a single 80MB JSON file import and the app didn't start or build?

Thanks for your help!


Solution

  • 80MB should not be a problem, but anyway you can try to open it using fs like a normal file and parse it to a Javascript object using JSON.parse.

    Hope it helps.

    Luis.