Fixing “WebAssembly.Instance(): Out of memory” Error in cPanel for Next.js/React.js Builds

If you’re building a Next.js or React.js application using the cPanel terminal and see the error “RangeError: WebAssembly.Instance(): Out of memory: Cannot allocate Wasm memory for new instance,” it means the build process needs more memory than cPanel is currently allowing.

Here’s how to fix this if you have WHM (WebHost Manager) access.

What Causes This Error?

Modern JavaScript applications, like those built with Next.js or React.js, can use a lot of memory during their build process. Sometimes, the tools they use (which might include WebAssembly for speed) try to use more memory than the limit set for a single process in your cPanel settings. When this happens, the build stops and shows the “Out of memory” error.

How to Fix It: Increase cPanel Process Memory Limit

You can solve this by increasing the maximum amount of memory a cPanel process can use. You’ll do this in WHM’s Tweak Settings.

  1. Log into WHM: Open your WHM panel. You usually do this by going to yourdomain.com/whm or yourserverip:2087 and logging in.
  2. Go to Tweak Settings: In WHM, look for “Tweak Settings.” You can often find it by typing “Tweak Settings” into the search bar.
  3. Find “Max cPanel process memory”: On the Tweak Settings page, you need to find the setting called “Max cPanel process memory.” You might see a note that the minimum is 4,096 MB.
  4. Increase the memory limit: You’ll need to increase the number in this field. The default or current setting might be too low for your application’s build process.
    • Try increasing it. For instance, if your server has enough resources, you could try 8,192 MB (8GB).
    • The exact amount you need can vary. If you still get the error, you might need to try a slightly higher value.
    • Be careful: Don’t set this value too high, as it could affect your server’s overall performance if other services don’t have enough memory. Keep an eye on your server’s total RAM usage.
  5. Save your changes: After changing the value, scroll down and click the “Save” button.

After you save the new setting, go back to the cPanel terminal and try building your Next.js or React.js application again. This should usually fix the “WebAssembly.Instance(): Out of memory” error.

In Short

This memory error happens when your application build needs more resources. Increasing the “Max cPanel process memory” through WHM Tweak Settings generally resolves the issue by giving the build process the memory it requires.