npm - How to set max-old-space-size in npm

19,478

Possibly you could try this,

> npm run start --node-flags --max-old-space-size=512 --no-warnings

> node --max-old-space-size=250 `which npm` some_npm_command
Share:
19,478
Sinu Varghese
Author by

Sinu Varghese

Updated on June 04, 2022

Comments

  • Sinu Varghese
    Sinu Varghese almost 2 years

    I am getting the below error while building the angular project,

    CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

    I have seen somewhere that configuring max-old-space-size in npm will solve the issue. But I don't know how to set it. I am using Windows OS & there are two npm files inside the nodejs installation folder (C:\Program Files\nodejs), npm & npm.cmd. First line inside the npm.cmd file is "Created by npm, please don't edit manually". So I am not supposed to edit this file & I have to configure max-old-space-size inside npm file. But I don't where in this file I have to configure it. My npm file looks like below,

    #!/bin/sh
    (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
    
    basedir=`dirname "$0"`
    
    case `uname` in
        *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
    esac
    
    NODE_EXE="$basedir/node.exe"
    if ! [ -x "$NODE_EXE" ]; then
      NODE_EXE=node
    fi
    
    NPM_CLI_JS="$basedir/node_modules/npm/bin/npm-cli.js"
    
    case `uname` in
      *MINGW*)
        NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
        NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
        if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
          NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
        fi
        ;;
      *CYGWIN*)
        NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
        NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
        if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
          NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
        fi
        ;;
    esac
    
    "$NODE_EXE" "$NPM_CLI_JS" "$@"