vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.71k stars 26.62k forks source link

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

Open IoanStoianov opened 1 year ago

IoanStoianov commented 1 year ago

Verify 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

Kraktoos commented 12 months ago

Getting the same issue with cPanel

omarqra commented 11 months ago

i am having the same problem with v13.5.3 on cpanel, when running build on Linux server : unhandledRejection RangeError: WebAssembly.instantiate(): Out of memory: wasm memory at lazyllhttp (eval at requireWithFakeGlobalScope (/home2/jeventeventreg/jevent-client/node_modules/next/dist/compiled/@edge-runtime/primitives/load.js:65:3), <anonymous>:9988:32) even though the server have alot of memory. @Kraktoos do you manage to solve this problem ?

Kraktoos commented 11 months ago

i am having the same problem with v13.5.3 on cpanel, when running build on Linux server : unhandledRejection RangeError: WebAssembly.instantiate(): Out of memory: wasm memory at lazyllhttp (eval at requireWithFakeGlobalScope (/home2/jeventeventreg/jevent-client/node_modules/next/dist/compiled/@edge-runtime/primitives/load.js:65:3), <anonymous>:9988:32) even though the server have alot of memory. @Kraktoos do you manage to solve this problem ?

Yeap, I downgraded some package versions. Here is a part of our updated package.json. The duplicate packages mean that the first one is the old one that didn't work and the latter one the one that fixed it. I don't know which specific package didn't work so that is why I'm sending this commit changes. Hope this helps.

"dotenv": "^16.3.1", "drizzle-orm": "^0.28.6", "eslint": "^8.49.0", "eslint-config-next": "^13.4.19", "eslint-config-next": "^12.0.4", "formidable": "^3.5.1", "ftp": "^0.3.10", "jsftp": "^2.1.3", "jsx-runtime": "^1.2.0", "lucide-react": "^0.277.0", "mysql2": "^3.6.1", "net": "^1.0.2", "next": "^13.4.19", "next": "13.4.8", "next-auth": "^4.23.1", "next-intl": "^2.20.0", "next-themes": "^0.2.1",@@ -72,11 +72,11 @@ "postcss": "8.4.29", "promise": "^8.3.0", "radix-ui": "^1.0.1", "react": "^18.2.0", "react": "18.2.0", "react-apexcharts": "^1.4.1", "react-chartjs-2": "^5.2.0", "react-day-picker": "^8.8.2", "react-dom": "^18.2.0", "react-dom": "18.2.0", "react-email": "^1.9.4", "react-parallax-tilt": "^1.7.166", "shadcn-ui": "^0.3.0",

omarqra commented 11 months ago

i am having the same problem with v13.5.3 on cpanel, when running build on Linux server : unhandledRejection RangeError: WebAssembly.instantiate(): Out of memory: wasm memory at lazyllhttp (eval at requireWithFakeGlobalScope (/home2/jeventeventreg/jevent-client/node_modules/next/dist/compiled/@edge-runtime/primitives/load.js:65:3), <anonymous>:9988:32) even though the server have alot of memory. @Kraktoos do you manage to solve this problem ?

Yeap, I downgraded some package versions. Here is a part of our updated package.json. The duplicate packages mean that the first one is the old one that didn't work and the latter one the one that fixed it. I don't know which specific package didn't work so that is why I'm sending this commit changes. Hope this helps.

"dotenv": "^16.3.1", "drizzle-orm": "^0.28.6", "eslint": "^8.49.0", "eslint-config-next": "^13.4.19", "eslint-config-next": "^12.0.4", "formidable": "^3.5.1", "ftp": "^0.3.10", "jsftp": "^2.1.3", "jsx-runtime": "^1.2.0", "lucide-react": "^0.277.0", "mysql2": "^3.6.1", "net": "^1.0.2", "next": "^13.4.19", "next": "13.4.8", "next-auth": "^4.23.1", "next-intl": "^2.20.0", "next-themes": "^0.2.1",@@ -72,11 +72,11 @@ "postcss": "8.4.29", "promise": "^8.3.0", "radix-ui": "^1.0.1", "react": "^18.2.0", "react": "18.2.0", "react-apexcharts": "^1.4.1", "react-chartjs-2": "^5.2.0", "react-day-picker": "^8.8.2", "react-dom": "^18.2.0", "react-dom": "18.2.0", "react-email": "^1.9.4", "react-parallax-tilt": "^1.7.166", "shadcn-ui": "^0.3.0",

it didn't work for my, its give me aborted (core dumped) which look like it it's memory issues with node on Linux

tjmosia commented 11 months ago

I am experiencing the exact same issue:

stderr: undefined:9972 return await WebAssembly.instantiate(mod, { ^

RangeError: WebAssembly.instantiate(): Out of memory: wasm memory at lazyllhttp (eval at requireWithFakeGlobalScope (/home/motocoil/nodevenv/app/webapp/18/lib/node_modules/next/dist/compiled/@edge-runtime/primitives/load.js:64:3), :9972:32)

Node.js v18.16.1

1w4nkx commented 8 months ago

hi, i have same issue. any update/idea to solve this issue?

i'm using CPanel with storage 4GB and 1GB memory (1core).

am i need to upgrade my cpanel? if yes, how about storage 8GB and 2GB memory(2core)

IoanStoianov commented 8 months ago

Sadly my workaround was to export my next.js app as a static page which I served with a standard express app. The drawback of my approach was that I couldn't use the benefits of the serverside components, caching, etc ...

imvad commented 7 months ago

We have this issue when on rocky linux as well.

0xrinegade commented 7 months ago

helpm im stuck too

AbuBakkarSiddiqueAnir commented 7 months ago

I am stuck on the issues for last three days, anyone got any workaround without downgrading the packages..!!

AbuBakkarSiddiqueAnir commented 7 months ago

I am stuck on the issues for last three days, anyone got any workaround without downgrading the packages..!!

this problem isn't showing till 12.3.4 ... when it is at 13.0.0, the nextjs taking much of memory to run

yas1nshah commented 7 months ago

any fix guys? i had been working on this app for months and now i cant even deploy it on a shared hosting (c-panel) it has 4GB Ram which is more than enough ig. image_2024-02-08_182203962

if anyone has any workaround do let me know

AbuBakkarSiddiqueAnir commented 7 months ago

any fix guys? i had been working on this app for months and now i cant even deploy it on a shared hosting (c-panel) it has 4GB Ram which is more than enough ig. image_2024-02-08_182203962

if anyone has any workaround do let me know

I worked around with that issue by downgrading the app 12.3.4 😶.

yas1nshah commented 7 months ago

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

Rehab-Osman commented 6 months ago

Build app before deploy to server and delete .next folder on server before deploy the new one after build. also u need to increase "max_execution_time" to make your app load fast

Maraoui21 commented 6 months ago

same issue here

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

aghamohammadi commented 3 months ago

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

Mem0Real commented 2 weeks ago

After pulling my hair out for so long, I managed to fix it. The above method sort of works (docker containerization) if you don't have to generate any specific env dependent outputs and is a bit cumbersome to do the whole process whenever you change something so this is how I went about it. I downloaded putty software to access the terminal from my pc. Follow this guide to achieve that. https://youtu.be/uP7Vo_tUAjs?si=rpQxmi3HR2K9HHqW

p.s. you have to use your own port number so contact your hosting provider if you don't know it. After successfully connecting to ssh, you just have to copy your files (without .next, node_modules, etc..) to a folder, go to the node software and create a server with the same name as the folder you've just created. You can copy the server.js code from the official Next Js documentation. After that, using putty, run npm install followed by npm run build. Restart the server and voila, your next js is now live.

I hope this helps. Good luck