ng build --prod有javaScript堆内存不足错误

时间:2018-02-21 13:16:45

标签: angular typescript npm

使用 ng build --prod 时,我遇到以下问题。

  

致命错误:CALL_AND_RETRY_LAST分配失败 - JavaScript堆   内存不足

尝试使用https://github.com/endel/increase-memory-limit增加尺寸限制 但它仍然无法建立。我是否需要在node_modules中的任何位置进行更改?

  

10%建筑模块6/8模块2有效   ... \ bootstrap \ dist \ css \ bootstrap 90%块资产处理< ---最后   几个GC --->

     

174152 ms:Mark-sweep 1266.2(1435.6) - > 1265.2(1435.6)MB,934.7 /   0.0 ms [分配失败] [请求旧空间中的GC]。 175021 ms:Mark-sweep 1265.2(1435.6) - > 1265.2(1435.6)MB,869.8 / 0.0 ms   [分配失败] [请求旧空间的GC]。 175964 ms:   标记扫描1265.2(1435.6) - > 1267.9(1410.6)MB,942.4 / 0.0 ms [最后   度假gc]。 176889 ms:Mark-sweep 1267.9(1410.6) - > 1271.4(1410.6)   MB,924.1 / 0.0 ms [最后的手段gc]。

     

< --- JS stacktrace --->

     

==== JS堆栈跟踪======================================== =

     

安全上下文:0000011C7D03FA99       1:getLast(又名getLast)[E:\ projects \ Nila Company \ memarane \ front-end \ node_modules \ escope \ lib \ pattern-visitor.js:~45]   [pc = 000002C336273AA1](这= 0000011C7D004241   ,xs = 0000037217E78589,xs = 0000037217E78589)       2:标识符[E:\ projects \ Nila Company \ memarane \ front-end \ node_modules \ escope \ lib \ pattern-visitor.js:76]   [pc = 000002C335B8874A](这= 0000037217E78539      

致命错误:CALL_AND_RETRY_LAST分配失败 - JavaScript堆   内存不足

我的依赖是:

  "dependencies": {
    "@angular/animations": "^4.0.0",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "@mm2/bsmodal": "^1.0.1",
    "@ng-bootstrap/ng-bootstrap": "1.0.0-beta.5",
    "@ngu/carousel": "^1.4.2",
    "angular-froala-wysiwyg": "^1.0.0",
    "angular-popper": "^1.0.0-beta-1",
    "angular2-jwt": "^0.2.3",
    "animate.css": "^3.5.2",
    "aos": "^2.2.0",
    "bootstrap": "4.0.0-beta.2",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jalali-moment": "^2.1.8",
    "jquery": "^3.2.1",
    "ng2-completer": "^1.6.1",
    "ng2-datepicker-jalali": "^1.0.9",
    "ng2-scroll-to-el": "^1.0.0",
    "ngx-carousel": "^1.3.1",
    "ngx-cookie-service": "^1.0.9",
    "ngx-progressbar": "^2.1.1",
    "ngx-quill": "^1.6.0",
    "ngx-quill-editor": "^2.2.2",
    "popper.js": "^1.12.9",
    "rxjs": "^5.4.1",
    "wowjs": "^1.1.3",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.1",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.2.16",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }

4 个答案:

答案 0 :(得分:2)

我在离子3单元测试中也遇到了同样的问题。

  

npm测试

在上面的命令中出现内存问题,然后通过下面的命令进行了修复-

  

npm安装

     

node --max_old_space_size = 8048 ./node_modules/@angular/cli/bin/ng测试

对我有用。

答案 1 :(得分:1)

您使用的是哪个打字稿版本?

如果它在2.x.x中,则更新到2.7.x,它们已经修复。

答案 2 :(得分:0)

添加maximumWarning和maximumError帮助我

“预算”:[ { “ type”:“ initial”, “ maximumWarning”:“ 5mb”, “ maximumError”:“ 12mb” }, { “ type”:“ anyComponentStyle”, “ maximumWarning”:“ 1mb”, “ maximumError”:“ 10mb” } ]

答案 3 :(得分:0)

这对我有用:

npm install increase-memory-limit -g

然后

increase-memory-limit

有关更多详细信息,您可以选中 AOT build fails due to "JavaScript heap out of memory