【问题标题】:Heap out of memory in angular4 while ng build --prod在 ng build --prod 时在 angular4 中堆内存不足
【发布时间】:2018-03-30 03:51:58
【问题描述】:

在 ng build --prod 时出现内存不足错误,是否有任何解决方法。当 --aot=false 时,它​​的构建很好。

有什么想法吗?

【问题讨论】:

  • node --max_old_space_size=4096

标签: angular


【解决方案1】:

尝试通过以下脚本在 json 包中运行构建脚本:

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

Reference

【讨论】:

    【解决方案2】:

    这是我根据上述帖子解决问题所采取的步骤,对我来说效果很好。

    第一步

    打开 package.json

    在脚本下添加这段代码

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

    第二步

    打开终端并运行执行此代码“npm run build-prod”

    希望对你有帮助

    【讨论】:

    • 所以唯一的改进就是使用./node_modules/.bin/ng而不是./node_modules/@angular/cli/bin/ng。因此,如果路径随时更改,您可以使用符号链接。
    【解决方案3】:

    我的团队也面临同样的问题,我们就是这样解决的。

    在构建项目而不是 ng build --prod 时使用这个

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

    或 只需像这样在您的 package.json 文件中添加上面的字符串并构建使用 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"
      },
    ...
    }
    

    在大型项目的情况下,将 --max_old_space_size 增加到 16384 到 64384。

    【讨论】:

    • 在大型项目的情况下,将 --max_old_space_size 增加到 16384 到 64384。
    【解决方案4】:
    export NODE_OPTIONS=--max_old_space_size=4096
    

    【讨论】:

    • 使用此方法在 CI/CD 期间导致的问题更少
    猜你喜欢
    • 1970-01-01
    • 2021-10-30
    • 2019-04-24
    • 1970-01-01
    • 2017-08-19
    • 2020-04-23
    • 2018-06-17
    • 1970-01-01
    • 2019-11-05
    相关资源
    最近更新 更多