Frappe App Build Failed - Javascript Heap out of Memory

Hi All,
I tried Fresh Setup by installing a Frappe using the easy install. The Installation say successful. But the css and js files were missing. When we dig deeper, we found that the build of frappe app failed with the following message “ineffective mark-compacts near heap limit allocation failed - javascript heap out of memory frappe”

Same Issue was already reported by @sonyvec. However the solution was not working.

Could some one help us in why this error is happening? how to solve this.

Thanks,
Saravana

I solved this by increasing max-old-size to 2048 and expanding my swap partition to 2gb (which should sum up to 2.5gb total ram on my raspberry, where .5gb are actual ram and 2 are swap).
If you can modify your swap on the go, remember to reboot your server

Wow! ERPNext on a raspberry?

I increased the swap size to 4GB. Still the same error.

I solved the issue. Might be helpful for other having the same. Downgrading Node version solves the issue.

Link: node.js - How to downgrade Node version - Stack Overflow
Step 1: npm install -g n

Step 2: n e.g n 8.17.0

Exit the terminal

Step 3: node -v
The downgraded version 8.17.0 should appear

Step 4:go to the frappe bench/apps/frappe

step 5: yarn install

step 6: sudo bench build --app frappe

Now Frappe is build successfully.

1 Like

What I’ve also done, to be able to keep the same version of Node is the following:

Go to: /home/frappe/frappe-bench/apps/frappe/node_utils.js

On lines:

“build”: “node rollup/build.js”,
“production”: “FRAPPE_ENV=production node rollup/build.js”,
“watch”: “node rollup/watch.js”

Change them to:

“build”: “node –max-old-space-size=8192 rollup/build.js”,
“production”: “FRAPPE_ENV=production node –max-old-space-size=8192 rollup/build.js”,
“watch”: “node –max-old-space-size=8192 rollup/watch.js”

This has solved the issue for me.

I’ve been trying to tackle this issue for quite some time. Usually adding some swap space helps, but it doesn’t guarantee anything. My PR to update Node’s memory usage dynamically by checking the availability before running rollup didn’t go anywhere.

So I’ve written a new feature which builds and maintains assets. This only works on develop and the next v13-beta. However, this feature enables assets to be packaged and attached to the GitHub releases that will be made henceforth. If you can craft an alternative script to utilize those assets instead of having to build on your servers.

https://github.com/frappe/frappe/pull/11436

Also, if you’re comfortable with docker, Frappe Docker could also work for you.

1 Like

I can’t find this part. I saw your screen short I was the same error.

 ubuntu@ip-172-31-15-5:/home/frappe/frappe-bench/apps/frappe$ nano node_utils.js
  GNU nano 2.9.3                                                                     node_utils.js

const fs = require('fs');
const path = require('path');
const redis = require('redis');
const bench_path = path.resolve(__dirname, '..', '..');

function get_conf() {
        // defaults
        var conf = {
                redis_async_broker_port: 12311,
                socketio_port: 3000
        };

        var read_config = function (file_path) {
                const full_path = path.resolve(bench_path, file_path);

                if (fs.existsSync(full_path)) {
                        var bench_config = JSON.parse(fs.readFileSync(full_path));
                        for (var key in bench_config) {
                                if (bench_config[key]) {
                                        conf[key] = bench_config[key];
                                }
                        }
                }
        }

        // get ports from bench/config.json
        read_config('config.json');
        read_config('sites/common_site_config.json');

        // detect current site
        if (fs.existsSync('sites/currentsite.txt')) {
                conf.default_site = fs.readFileSync('sites/currentsite.txt').toString().trim();
        }

        return conf;
}

function get_redis_subscriber() {
        const conf = get_conf();
        const host = conf.redis_socketio || conf.redis_async_broker_port;
        return redis.createClient(host);
}

module.exports = {
    get_conf,
    get_redis_subscriber
}

Hi, things mentioned by @sonyvec can be found in package.json file.