Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gatsby/netlify CMS - javascript heap out of memory

Gatsby and Netlify CMS were running nicely for a while but now it fails when trying to run gatsby develop. With a "JavaScript heap out of memory" error.

Every npm is updated and I've tried export NODE_OPTIONS=--max_old_space_size=4096 that some GitHub issue threads mention.

like image 304
TrevPennington Avatar asked Sep 21 '20 21:09

TrevPennington


1 Answers

You hit the nail with the command to fix it:

export NODE_OPTIONS=--max_old_space_size=4096

However, adding the previous script in the terminal will fix it locally, it may work if your gatsby develop or gatsby build fails but not in the server.

To fix it there in the server (Netlify side), you need to reach to the nettlify-cli. The easiest way to do it is by adding a file named netlify.toml in the root of your project with the following content.

[build.environment]
  NODE_OPTIONS = "--max_old_space_size=4096"

Basically you are setting the Node options when Netlify builds the site exactly in the same way you did it in the terminal.

The issue comes from the Node side; it seems that the extra transpiling being done is just now making Node hit its default limit without increasing it automatically.

If you need more information about the netlify.toml file check out the File-based configuration documentation of Netlify.

like image 166
Ferran Buireu Avatar answered Oct 10 '22 20:10

Ferran Buireu