JavaScript heap out of memory
after
wasp start or wasp build:
-----
running export NODE_OPTIONS="--max-old-space-size=8192" command fixes it but what about this?16 Replies
Hi @NEROX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error message you’re seeing—“JavaScript heap out of memory” during
Using
wasp start or wasp build—is related to Node.js running out of memory while building or running your Wasp project. This is a known issue, especially on machines with limited RAM or when the frontend build process is particularly heavy.
From the knowledge sources:
- Wasp’s frontend build process (previously with Create React App, now with Vite) can consume a significant amount of memory. Earlier, it could take up to 1GB, but switching to Vite reduced this to around 200–300MB. However, in some environments or larger projects, memory usage can still be high and may exceed the default Node.js heap size, leading to the error you encountered. Suggestions to reduce memory usage include disabling source maps or limiting RAM via flags, but these are general Node.js/React build tips and not Wasp-specific solutions ‘wasp start’ takes a lot of memory (~1 GB) to run frontend.
- Setting NODE_OPTIONS="--max-old-space-size=8192" increases the memory limit for Node.js and is a common workaround for this issue. This is not Wasp-specific but is a standard Node.js solution for memory-intensive builds.
- On low-memory environments (e.g., VPS with 512MB or 1GB RAM), Wasp may struggle to run due to the number of processes and memory required. Community members have reported similar issues and found that increasing available memory or using the NODE_OPTIONS workaround helps OpenSaas setup 'Role postgres does not exist', Whenever I run wasp db migrate-dev on my ec2 instance (micro free tier) it causes the box to hang.
Summary:Using
export NODE_OPTIONS="--max-old-space-size=8192" is a valid and effective workaround for the “heap out of memory” error. There is no Wasp-specific fix documented in the knowledge sources; the issue is due to the underlying Node.js process running out of memory during build or development. If you continue to experience issues, consider running Wasp on a machine with more RAM or optimizing your project to reduce memory usage during builds.
If you need more targeted optimization, you may try disabling source maps or limiting other build features, but these are general Node.js/React/Vite optimizations and not specific to Wasp. The knowledge sources do not provide a Wasp-specific configuration to address this beyond the standard Node.js workaround.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?@kapa.ai project getting bigger, will this affect production in any way?
Let me check the knowledge base for you again. One moment! :books:
----------------------
As your Wasp project grows larger, it can impact both development and production environments, primarily in terms of build times and memory usage. The knowledge sources indicate that memory usage during development and build processes can be significant, especially for the frontend. For example, the frontend build process previously consumed up to 1GB of RAM, though this has improved with the switch to Vite (now around 200–300MB in typical cases). However, larger projects may still require more memory, and you might encounter "heap out of memory" errors if the available memory is insufficient ‘wasp start’ takes a lot of memory (~1 GB) to run frontend.
For production, the main concern is ensuring that your deployment environment has enough resources (RAM and CPU) to handle the increased demands of a larger application. There is no explicit mention in the knowledge sources of Wasp-specific production issues caused by project size, but general Node.js and frontend build considerations apply. If your production server has limited memory, you may need to increase it to avoid build or runtime failures, especially during deployment when building the app.
In summary, as your project grows, you should monitor and potentially increase your production server's resources to ensure smooth builds and operation. The knowledge sources do not mention any Wasp-specific production limitations related to project size beyond these general considerations.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
@kapa.ai
package.json:
"scripts": {
"start": "NODE_OPTIONS='--max-old-space-size=8192' wasp start",
"start:dev": "NODE_OPTIONS='--max-old-space-size=8192' wasp start",
"build": "NODE_OPTIONS='--max-old-space-size=8192' wasp build",
"clean": "wasp clean",
"db:start": "wasp start db",
"db:migrate": "wasp db migrate-dev"
},
Is this correct? any comments?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Your
Your scripts are correct and follow best practices as discussed in the Wasp community for handling memory issues during build and start. No issues or concerns are raised in the knowledge sources regarding this approach. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
package.json scripts look reasonable for working around the Node.js memory limit issue by setting NODE_OPTIONS='--max-old-space-size=8192' for wasp start and wasp build. This is a common and effective workaround for "heap out of memory" errors, as discussed in the knowledge sources. There is no indication in the sources that this approach would cause problems for Wasp, and it aligns with community recommendations for handling memory-intensive builds ‘wasp start’ takes a lot of memory (~1 GB) to run frontend.
A few comments based on the knowledge sources:
- The use of wasp clean, wasp start db, and wasp db migrate-dev in your scripts is consistent with Wasp's CLI commands and their intended usage CLI Reference > Project Commands.
- There is no mention in the knowledge sources of any issues with setting NODE_OPTIONS in this way for Wasp commands.
- If you are deploying to environments where the default shell is not POSIX-compliant (e.g., Windows), you may need to adjust the syntax for setting environment variables, but this is a general Node.js/JavaScript consideration and not Wasp-specific.
Summary:Your scripts are correct and follow best practices as discussed in the Wasp community for handling memory issues during build and start. No issues or concerns are raised in the knowledge sources regarding this approach. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
@kapa.ai doing wasp build i get again this problem
Let me check the knowledge base for you again. One moment! :books:
----------------------
If you are still encountering the "JavaScript heap out of memory" error when running
wasp build—even after setting NODE_OPTIONS='--max-old-space-size=8192'—this indicates that the build process is exceeding the memory limit you set, or that the environment variable is not being picked up correctly by the build process.
From the knowledge sources, this is a known issue for larger projects or on machines with limited memory. The recommended workaround is to increase the Node.js memory limit using NODE_OPTIONS, as you have done. There are no Wasp-specific fixes documented beyond this approach ‘wasp start’ takes a lot of memory (~1 GB) to run frontend.
Possible reasons you might still see the error:
- The environment variable syntax may not be compatible with your shell or OS (e.g., on Windows, you need to use set NODE_OPTIONS=... instead of NODE_OPTIONS=...).
- Your project may require even more memory than 8GB, especially if it has grown significantly.
- There may be another underlying issue with a dependency or the build process, but the knowledge sources do not provide details on further troubleshooting steps.
What you can try:
- Double-check that the NODE_OPTIONS variable is being set correctly for your environment.
- Try increasing the value further, e.g., --max-old-space-size=16384 (if your machine has enough RAM).
- Make sure no other processes are consuming excessive memory during the build.
If the problem persists, the knowledge sources do not provide additional Wasp-specific solutions. You may need to optimize your project to reduce memory usage or consider building on a machine with more available RAM.
If you have more details about your environment or the specific error output, please share them for more targeted help.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?@kapa.ai but error shows that it only uses 2gb, how can I implement the 8192 so never i need to run the command? why the package options dont work?
Let me check the knowledge base for you again. One moment! :books:
----------------------
The knowledge sources do not provide a Wasp-specific solution for ensuring that
The knowledge sources confirm that using
NODE_OPTIONS='--max-old-space-size=8192' is always applied during wasp build or wasp start. Setting NODE_OPTIONS in your package.json scripts is a standard Node.js approach, but whether it works depends on your operating system and shell.
Why might the package.json scripts not work?
- On some systems (especially Windows), the syntax NODE_OPTIONS='--max-old-space-size=8192' wasp build does not set the environment variable as expected. On Windows, you need to use set NODE_OPTIONS=--max-old-space-size=8192 && wasp build instead.
- If the environment variable is not set correctly, Node.js will use its default memory limit (about 2GB), which matches the error you are seeing.
How to ensure it always works?
- Make sure you use the correct syntax for your OS.
- Alternatively, you can set the environment variable globally in your shell profile (e.g., in .bashrc, .zshrc, or system environment variables), so it is always available when running any Node.js process, including Wasp.
Summary:The knowledge sources confirm that using
NODE_OPTIONS is the recommended workaround, but do not provide a Wasp-specific way to enforce it. If your package.json scripts are not working, it is likely due to environment variable syntax or OS compatibility, not a limitation of Wasp itself ‘wasp start’ takes a lot of memory (~1 GB) to run frontend.
If you need a persistent solution, set NODE_OPTIONS globally in your environment, or ensure your script syntax matches your OS requirements.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Hey @NEROX, I see you're talking with the bot. Tag me if you need human help
Well, as the project is getting bigger now I run
NODE_OPTIONS='--max-old-space-size=8192' wasp start instead of wasp start.
My package.json:
But it doesn't work, any way to set this? To just run wasp start as alwaysHm, can you elaborate? What exacly do you want to do?
I don't want to run the
NODE_OPTIONS='--max-old-space-size=8192' command before wasp start or wasp build.
If I don't run it, it gives me the JavaScript heap out of memory error.
But I tried setting the commands in the package.json but they didn't anything.
So I don't know if it's possible to set that space value forever
Oh, I see
You can't do it in package.json because those are npm commands (so you're editing what happens when you run
npm run start)
What you can do is either:
- Set the env variable in the terminal/shell by running: export NODE_OPTIONS='--max-old-space-size=8192'. After you do this, all wasp start and wasp build commands will take it into account (and any other commands you may run). It's visible to all the terminal's subprocesses.
- Create an alias for NODE_OPTIONS='--max-old-space-size=8192' wasp by running alias bigwasp="NODE_OPTIONS='--max-old-space-size=8192' wasp" and then running bigwasp start and bigwasp build
I prefer the first option, so:
So I don't know if it's possible to set that space value foreverWhile @Filip has offered valid solutions, both options are session-scoped, so if you want to set the value forever, you'll have to add either command to your shell startup file (e.g. .bashrc or .zshrc) for it to be persisted across all sessions
That's a great point! Thanks @genyus