javascript - fatal error : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory Angular 13 application

标签 javascript angular typescript eslint angular-eslint

我已将 Angular 应用程序从 12 升级到 13,并添加了 eslint 和 Prettier。

在执行 ng lint 时,我遇到以下错误

macbook@macbooks-MacBook-Air LegalRegTech.Web.Host % ng lint

Linting "abp-zero-template"...

<--- Last few GCs --->

[18697:0x7f8814800000]   899728 ms: Mark-sweep (reduce) 2036.5 (2081.8) -> 2035.8 (2082.5) MB, 6232.4 / 0.0 ms  (average mu = 0.155, current mu = 0.048) allocation failure scavenge might not succeed
[18697:0x7f8814800000]   906650 ms: Mark-sweep (reduce) 2036.1 (2082.5) -> 2036.0 (2082.5) MB, 6313.6 / 0.0 ms  (average mu = 0.122, current mu = 0.088) allocation failure GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x101c5a0e5 node::Abort() [/usr/local/bin/node]
 2: 0x101c5a268 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x101dd0597 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x101dd0533 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x101f6ee55 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 6: 0x101f72e7b v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node]
 7: 0x101f6f75c v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x101f6cc0a v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x101f79f60 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x101f79fe1 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x101f46f37 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
12: 0x1022f2fbf v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
13: 0x102694d99 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
14: 0x106be229f 
zsh: abort      ng lint

这是 eslint 配置

{
  "root": true,
  "ignorePatterns": [
    "projects/**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "src/tsconfig.json",
          "e2e/tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "plugins": ["prettier"],
      "rules": {
        "prettier/prettier": ["error"],
        "@angular-eslint/component-selector": [
          "error",
          {
            "prefix": "app",
            "style": "kebab-case",
            "type": "element"
          }
        ],
        "@angular-eslint/directive-selector": [
          "error",
          {
            "prefix": "app",
            "style": "camelCase",
            "type": "attribute"
          }
        ]
      }
    },
    {
      "files": [
        "*.html"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {}
    }
  ]
}

package.json 中的脚本

"scripts": {
    "ng": "ng",
    "publish": "ng build --prod",
    "start": "ng serve --host 0.0.0.0 --port 4200",
    "hmr": "ng serve --host 0.0.0.0 --port 4200 --hmr",
    "test": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "verbose": "ng serve --host 0.0.0.0 --port 4200 --verbose",
    "bundle-report": "webpack-bundle-analyzer dist/stats.json",
    "analyze": "ng build --prod --stats-json && webpack-bundle-analyzer dist/stats.json",
    "memstart": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --port 4200",
    "start-dev": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --port 4200 --configuration=development --open",
    "lint": "ng lint"
  },

最佳答案

您遇到了 ngserve 的内存限制。尝试增加限制:

package.json

"serve": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve"

关于javascript - fatal error : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory Angular 13 application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70093609/

相关文章:

javascript - JQuery获取标签内的html字符串

javascript - 如何让代码等待确定/取消按钮选择?

dart - Angular2:导航到路由并弹出回到pushState堆栈的根

javascript - 在 React 中重置子组件中的选项卡

typescript - 实现可观察对象默认 setter 行为的 Nativescript 类

javascript - 具有 10k 数据点的数据集的 Highcharts 替代方案?

AJAX 调用后 Javascript 文件不执行

unit-testing - Angular 2. 在单元测试中发出悬停事件

angular - 模拟对象如何在 Angular jasmine 单元测试中工作

javascript - 从对象类型的字符串值创建字符串文字类型