npm run build throws error on production server – FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

blog image

This error occurs because the JavaScript heap memory limit is exceeded during the build process, causing the Node.js process to crash. This can happen when the build process requires more memory than the default heap limit allocated by Node.js.

To resolve this issue, you can increase the memory limit allocated to Node.js during the build process by setting the NODE_OPTIONS environment variable. Here’s how you can do it:

  1. Open a terminal and navigate to your project’s root directory.
  2. Run the following command to set the NODE_OPTIONS environment variable:
pythonCopy codeexport NODE_OPTIONS=--max-old-space-size=4096

This sets the maximum heap size to 4GB (4096MB). 3. Run the build command again:

Copy codenpm run build

This time, the build process should complete without the out of memory error.

If you need to allocate more memory, you can increase the max-old-space-size value accordingly. However, keep in mind that allocating too much memory can also cause performance issues.

×
×

Ready to scale up your business?

Follow Us