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

前端 未结 4 1420
时光说笑
时光说笑 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.

提交回复
热议问题