Heap out of memory in angular4 while ng build --prod

前端 未结 4 1413
时光说笑
时光说笑 2020-12-25 13:39

I am getting an heap out of memory error while ng build --prod ,Is there any work around. its building fine when --aot=false.

Any idea ?

相关标签:
4条回答
  • 2020-12-25 14:11

    My team was facing the same issue and this is how we resolved.

    While building the project instead of ng build --prod use this

    node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer
    

    OR Just add above string in your package.json file like this and to build use just npm run prod,

        {
      "name": "Deva_Application",
      "version": "1.0.0",
        "scripts": {
        "ng": "ng",
        "start": "ng serve  --proxy-config proxy.conf.json",
        "prod": "node --max_old_space_size=64384  ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer --output-hashing=none",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
      },
    ...
    }
    

    In case of large project increase the --max_old_space_size to 16384 to 64384.

    0 讨论(0)
  • 2020-12-25 14:27

    Try running build script in package json by the following script:

    "scripts": {
       "build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod"
    }
    

    Reference

    0 讨论(0)
  • 2020-12-25 14:29
    export NODE_OPTIONS=--max_old_space_size=4096
    
    0 讨论(0)
  • 2020-12-25 14:36

    Here are the steps i have done to fix the issue based on above post and its worked well for me.

    Step-1

    Open package.json

    Add this code under scripts

    "build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod"

    Step-2

    Open terminal and run execute this code "npm run build-prod"

    Hope this helps

    0 讨论(0)
提交回复
热议问题