Angular应用突然失败-“ JavaScript堆内存不足”

时间:2018-10-30 12:44:12

标签: angular-cli

使用Angular-cli进行服务时,我突然遇到此错误。这是什么意思,如何找到错误?

我一直在使用angular.json文件,但是在发生这种情况之前根本没有接触过源代码。

我可以通过某种方式获得有关此错误的更多信息吗?可以调试吗?

[8472:0000027E1D943100]   199982 ms: Mark-sweep 1244.7 (1484.0) -> 1244.6 (1488.0) MB, 1490.9 / 2.5 ms  allocation failure GC in old space requested
[8472:0000027E1D943100]   201455 ms: Mark-sweep 1244.6 (1488.0) -> 1244.5 (1446.5) MB, 1473.7 / 2.8 ms  last resort GC in old space requested
[8472:0000027E1D943100]   202974 ms: Mark-sweep 1244.5 (1446.5) -> 1244.5 (1439.5) MB, 1518.3 / 2.7 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 000000F103425879 <JSObject>
    1: push(this=00000396CD788A21 <JSArray[579629]>)
    2: /* anonymous */ [C:\Apache24\htdocs\myproject\node_modules\readdirp\readdirp.js:~177] [pc=0000006E6B5D6C9D](this=000002313C98C2F1 <JSGlobal Object>,err=000000088F582201 <null>,stat=000002E4C4DA0851 <Stats map = 000003BC493C0269>)
    3: /* anonymous */ [C:\Apache24\htdocs\myproject\node_modules\graceful-fs\polyfills.js:287] [bytecode=...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node_module_register
 2: v8::internal::FatalProcessOutOfMemory
 3: v8::internal::FatalProcessOutOfMemory
 4: v8::internal::Factory::NewUninitializedFixedArray
 5: v8::internal::WasmDebugInfo::SetupForTesting
 6: v8::internal::WasmDebugInfo::SetupForTesting
 7: v8::internal::WasmDebugInfo::SetupForTesting
 8: v8::internal::WasmDebugInfo::SetupForTesting
 9: v8::internal::SharedFunctionInfo::SetScript
10: v8::internal::JSReceiver::class_name
11: v8::internal::SourcePositionTableIterator::Advance
12: v8::internal::SourcePositionTableIterator::Advance
13: 0000006E6B4843C1

2 个答案:

答案 0 :(得分:0)

在旧的Angular cli中,它发生在大型代码库上……一种可能的解决方法是对ngc.cmd文件(在Windows上)进行一些修改,并增加

--max_old_space_size=8192

希望它对您有帮助

答案 1 :(得分:0)

好的,我想我找到了原因,在angular.json文件中,我的“ assetts”部分如下所示,并引用了我想包含在构建中的外部文件。进行“ ng服务”时,这似乎是一个问题。

我的解决方案是在开发过程中排除这部分,而在将其投入生产时放回原处。

是否有一种方法可以指定仅在执行此操作时才包含此资产 “ build --prod”?

"assets": [
              "src/.htaccess",
              "src/favicon.ico",
              "src/assets",
              "src/api",
              "src/app/img",

  {"input": "C:/apache/htdocs/api",
   "glob": "apiconfig.php",
   "output": "apiconfig" }
]