next.js: "RangeError: WebAssembly.instantiate(): Out of memory: wasm memory" when using environment with limited virtual memory

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

/app # npx next info

    Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Thu May 25 07:17:40 UTC 2023
    Binaries:
      Node: 16.20.0
      npm: 8.19.4
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.3.3
      eslint-config-next: 13.4.2
      react: 18.2.0
      react-dom: 18.2.0

/app # ulimit -a 
core file size (blocks)         (-c) 0
data seg size (kb)              (-d) unlimited
scheduling priority             (-e) 0
file size (blocks)              (-f) unlimited
pending signals                 (-i) 63574
max locked memory (kb)          (-l) 82000
max memory size (kb)            (-m) 2048000
open files                      (-n) 1048576
POSIX message queues (bytes)    (-q) 819200
real-time priority              (-r) 0
stack size (kb)                 (-s) 8192
cpu time (seconds)              (-t) unlimited
max user processes              (-u) unlimited
virtual memory (kb)             (-v) 2048000
file locks                      (-x) unlimited

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://github.com/IoanStoianov/limited-virtual-memory-nextjs/tree/main

To Reproduce

Clone the limited-virtual-memory-nextjs and follow the Readme

Local:

  1. Limit the virtual memory of your environment. I tried it on docker image node:16.20.0-alpine - ulimit -v 2048000
  2. Install version higher than 13.3.3
  3. Run npx next info
  4. Get: RangeError: WebAssembly.instantiate(): Out of memory: wasm memory    at lazyllhttp (node_modules/next/dist/compiled/undici/index.js:1:55249)

Describe the Bug

This behavior happens when I upgrade to a version higher than 13.3.3. I cannot run even npx next info

Expected Behavior

To be able to perform next commands on environment with limited virtual memory

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

I deployed the app on my client’s cPanel

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 7
  • Comments: 28

Most upvoted comments

Getting the same issue with cPanel

In version 13.5.6, it worked for me, definitively!!! After testing various methods, I finally resolved the memory error issue RangeError: WebAssembly.instantiate(): Out of memory: wasm memory using this approach.

1- To deploy, don’t fetch the app build from the cpanel terminal. Instead, obtain it locally and upload the .next folder to the cpanel host. Otherwise, the memory error persists.

2- Note that if your local operating system is Windows and you’ve built the Next.js app on a Windows system, the built version won’t work on a Linux cpanel host. You’ll need Docker assistance.

3- First, run the app on Docker, then extract the .next folder from the Docker image to your local system. Upload the .next folder to the cpanel host, and you’ll see the site running smoothly.

4- Here’s a simple Dockerfile for creating a Docker image:

FROM node:20.9.0

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install
COPY . .

RUN npm run build

CMD ["npm", "start"]

5- Build the image in CMD:

docker build -t nextjs-sample .

6- Extract the .next folder from the Docker image. Pay attention to the paths; the first path is for Docker, the second for extraction on the local system, and container_id is the container code, in CMD.

docker cp [container_id]:/usr/src/app/build /output

7- Upload “.next” folder to cpanel host

Error: Image

Hello. I had the same problem with Cpanel. Doing a little research. I discovered that the problem is in the cpanel terminal, which has certain limitations. So the solution for 2025 is to configure SSH access using putty, so you can use a terminal without limitations like cpanel. Here is the evidence that it works.

Image

My Hosting is shared and only has 2 memory for my plan. With SSH access through putty I was able to solve the memory problem, which was really the memory of the Cpanel terminal and not my hosting.

also u can try to install other node versions 18 will work here : 1

uninstalled v20 and installed v18 and works perfectly : 2

if you have a whm server SSH and just install to that specific CPAnel user and it will work

Hi @Shoyas 👋 How do you restart your app? Do you have a repo I could look at?

Managed to deploy a Next.js 14.2.4 app to CPanel through GitHub Actions. Got a wee guide; hopefully that helps 🙏

downgraded to v12? then it wont use the app router and other next features. in that case Next Js is useless to me.