javascript - fatal error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory error

标签 javascript node.js angular memory-leaks build

我在运行 ng build --prod

时遇到此错误

92% chunk asset optimization <--- Last few GCs --->

[4136:0155D210] 443646 ms: Mark-sweep 703.5 (770.3) -> 703.6 (759.8) MB, 2162.2 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 2163 ms) last resort GC in old space requested [4136:0155D210] 445794 ms: Mark-sweep 703.6 (759.8) -> 703.5 (759.8) MB, 2147.8 / 0.0 ms last resort GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0369632D 1: create(this=036856A9 ) 2: _walk [034841A1 :~764] [pc=1CCAED1F](this=3A11A619 ,visitor=3BCEFD7D ) 3: /* anonymous */ [034841A1 :~969] [pc=1D3728E3](this=3A11BCBD ) 4: _walk [034841A1 :~968] [pc=1CCC1F3B](this=3A11BCBD

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node_module_register 2: v8::internal::Factory::NewStruct 3: v8::internal::Factory::NewPrototypeInfo

我什么都试过了。我减少了变量的使用并检查了内存泄漏并在 ts 文件中进行了非常少的回调。

我不知道该怎么做。我尝试使用 'npm i increase-memory-limit' 增加 Node 内存并将限制增加到 2GB

我使用的是 angular 4。Node 版本是 8.9.4

最佳答案

尝试导航到您的项目/node_modules 并运行以下命令:

node --max_old_space_size=5048 "%~dp0\..\@angular\cli\bin\ng" build --aot --prod

如果你想让你的生活更轻松,你可以将它插入到你的 package.json 文件中:

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

然后您现在要做的就是运行 npm run build-prod

关于javascript - fatal error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50621043/

相关文章:

node.js - 为什么 Express 在安装时创建 Sym 链接?

node.js - 如何将 package.json 中的每个依赖项更新到最新版本?

angular - 当 RouteReuseStrategy 恢复时,angular2-component 如何知道它处于事件状态?

javascript - Jasmine 单元测试中仅模拟今天的日期

javascript - Jquery 克隆只重复一次。需要重复多次

node.js - Heroku 服务器上 NodeJS 应用程序中 MissingSchemaError

angular - 错误 : NullInjectorError: No provider for FlashMessagesService

javascript - 每个字母在文本区域(输入)中的随机字距调整

javascript - Eloquent JavaScript : Can't understand recursion example

javascript - 必须刷新页面才能从 api 获取数据