MarkCompactCollector: young object promotion failed Allocation failed

I have cloned a git repository containing a Vue project locally using git clone. I then ran npm install to install the dependencies and got the node_modules folder.

On running npm run serve I get the following error:

[11920:03BEA178]   321556 ms: Scavenge (reduce) 429.1 (464.7) -> 429.1 (464.7) MB, 37.7 / 17.8 ms  (average mu = 0.980, current mu = 0.932) allocation failure
[11920:03BEA178]   321643 ms: Scavenge (reduce) 429.7 (465.2) -> 429.7 (465.2) MB, 61.2 / 0.9 ms  (average mu = 0.980, current mu = 0.932) allocation failure
[11920:03BEA178]   321765 ms: Scavenge (reduce) 432.2 (467.3) -> 432.2 (467.3) MB, 22.1 / 0.0 ms  (average mu = 0.980, current mu = 0.932) allocation failure


<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] serve: `vue-cli-service serve --open`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UserssagarAppDataRoamingnpm-cache_logs2020-12-10T09_32_00_595Z-debug.log

Also, my node_modules folder is about 8GB in size. I’m running this on a convertible with 2GB RAM.

Answer

The way I managed to get past this error was by turning off minimization for TerserPlugin in webpack.config.js as follows:

const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
optimization: {
    minimize: false,
    minimizer: [new TerserPlugin()],
  },
};

This might not work for everyone as, in my opinion, this error occurs when the RAM isn’t sufficient. I didn’t have to set minimize to false when I ran the app on a laptop with 4GB RAM with much more hard disk space. You can set minimize to false in the development stage and set it back to true when the app is production ready.

Leave a Reply

Your email address will not be published. Required fields are marked *