【问题标题】:Ineffective mark-compacts near heap limit Allocation Angular 8 - JavaScript heap out of memory接近堆限制的无效标记压缩分配Angular 8 - JavaScript堆内存不足
【发布时间】:2020-03-13 21:56:55
【问题描述】:

42% 建造 274/275 个模块 1 个活跃 ...\src\index.js??extracted!D:\Clients\app\node_modules\sass-loader\lib\loader.js??ref--15-3!D:\src\styles.scss

[12996:000002DFC57D42F0] 43111 毫秒:清除 1335.4 (1425.0) -> 1335.3 (1426.0) MB, 2.6 / 0.0 ms (平均 mu = 0.169, 当前 mu = 0.100) 分配失败 [12996:000002DFC57D42F0] 43489 ms: Mark-sweep 1336.2 (1426.0) -> 1335.4 (1425.0) MB, 375.8. (平均 mu = 0.144,当前 mu = 0.100)分配失败清除 可能不会成功

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

0: ExitFrame [pc: 00000257D3FDC5C1] Security context: 0x00b77541e6e9 <JSObject>
1: createNode [000001A31ED4EFF1] [D:\Clients\app\node_modules\typescript\lib\typescript.js:~16489]

[pc=00000257D55AD889](this=0x02b823cedf89 ,kind=275,pos=-=-1,end=-1) 2:createPropertyAssignment [000001A31ED54669] [D:\Clients\app\node_modules\typescript\lib\typescri...

致命错误:在堆限制分配附近标记压缩无效 失败 - JavaScript 堆内存不足 1: 00007FF76C26DD8A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506 2: 00007FF76C248886 节点::MakeCallback+4534 3: 00007FF76C249200 节点模块寄存器+2032 4:00007FF76C5630DE v8::internal::FatalProcessOutOfMemory+846 5:00007FF76C56300F v8::internal::FatalProcessOutOfMemory+639 6:00007FF76C749804 v8::internal::Heap::MaxHeapGrowingFactor+9620 7:00007FF76C7407E6 v8::内部::ScavengeJob::操作员=+24550 8:00007FF76C73EE3C v8::内部::ScavengeJob::操作员=+17980 9:00007FF76C747B87 v8::internal::Heap::MaxHeapGrowingFactor+2327 10:00007FF76C747C06 v8::internal::Heap::MaxHeapGrowingFactor+2454 11:00007FF76C871EA7 v8::internal::Factory::NewFillerObject+55 12:00007FF76C8EF096 v8::internal::operator

我已经尝试过这个解决方案:https://github.com/angular/angular-cli/issues/5618#issuecomment-450151214

package.json

"scripts": {
        "ng": "ng",
        "ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",// here
        "start": "ng serve",
        "build:prod": "ng build --configuration=prod",
    },

之后

npm 运行 ng-high-memory --build --prod

但它说

> > metronic-angular@6.0.0 ng-high-memory D:\Clients\app
> > node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng
> 
> Available Commands:   add Adds support for an external library to your
> project.   analytics Configures the gathering of Angular CLI usage
> metrics. See https://v8.angular.io/cli/usage-analytics-gathering.  
> build (b) Compiles an Angular app into an output directory named dist/
> at the given output path. Must be executed from within a workspace
> directory.   deploy (d) Invokes the deploy builder for a specified
> project or for the default project in the workspace.   config
> Retrieves or sets Angular configuration values in the angular.json
> file for the workspace.   doc (d) Opens the official Angular
> documentation (angular.io) in a browser, and searches for a given
> keyword.   e2e (e) Builds and serves an Angular app, then runs
> end-to-end tests using Protractor.   generate (g) Generates and/or
> modifies files based on a schematic.   help Lists available commands
> and their short descriptions.   lint (l) Runs linting tools on Angular
> app code in a given project folder.   new (n) Creates a new workspace
> and an initial Angular app.   run Runs an Architect target with an
> optional custom builder configuration defined in your project.   serve
> (s) Builds and serves your app, rebuilding on file changes.   test (t)
> Runs unit tests in a project.   update Updates your application and
> its dependencies. See https://update.angular.io/   version (v) Outputs
> Angular CLI version.   xi18n Extracts i18n messages from source code.
> 
> For more detailed help run "ng [command name] --help"

那么我怎样才能正确运行这个命令呢?

注意:我使用最新的 Angular 即 "@angular/core": "^8.2.14""@angular/cli": "^8.3.19"

【问题讨论】:

    标签: node.js angular typescript


    【解决方案1】:

    将 node js 版本升级到 v12 或比您当前使用的版本更高的版本。

    【讨论】:

    • 安装 node -v v12.16.1 对我有用。谢谢!
    【解决方案2】:

    这可能看起来很荒谬,但 !=== 而不是 !== 在我的情况下导致了这个问题。因此,请检查您的代码是否有任何拼写错误。

    【讨论】:

      【解决方案3】:

      解决后增加节点最大内存大小

      // terminal
      export NODE_OPTIONS=--max_old_space_size=8096
      
      // Windows
      set NODE_OPTIONS=--max_old_space_size=8096
      

      【讨论】:

        【解决方案4】:
        export NODE_OPTIONS=--max_old_space_size=8192
        

        export 为我工作,而不是 set。我从包含测试文件的父目录中的终端运行它。

        【讨论】:

          【解决方案5】:

          您分配的内存即将用完。

          在您的项目目录中,运行此命令。

          set NODE_OPTIONS=--max_old_space_size=8192
          

          (这设置了 8GB 内存分配)。

          那么,

          ng serve --openng build --prod

          或者 像这样使用,

          set NODE_OPTIONS=--max_old_space_size=8192 & ng serve --open
          

          为了避免每次都将所有这些都输入到一起,我们可以将此脚本保存在 package.json 文件中。

          里面 “脚本”:{....}

          "scripts": {
              .....
              "mserve":"set NODE_OPTIONS=--max_old_space_size=8192 & ng serve --open"
              }
          

          然后在终端中,在您的项目中。 跑步

          npm run mserve
          

          您可以将 mserve 重命名为您想要的任何名称

          【讨论】:

            【解决方案6】:

            我收到此错误,但就我而言,问题与 angular.json 设置有关。它与“预算”设置有关。

            原来是这样的……

             "budgets": [
                            {
                              "type": "initial",
                              "maximumWarning": "2mb",
                              "maximumError": "5mb"
                            },
                            {
                              "type": "anyComponentStyle",
                              "maximumWarning": "6kb",
                              "maximumError": "10kb"
                            }
                          ]
            

            修复后...看起来像这样...

                "budgets": [
                    {
                      "type": "anyComponentStyle",
                      "maximumWarning": "6kb"
                    }
                  ],
            

            【讨论】:

              【解决方案7】:

              我在 cmd 上使用了以下命令,而不是从 package.json 修复内存问题。这对我有用。

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

              我使用的是 Angular 6,我不必升级到最新版本的 Angular。这个错误与我猜的角度版本无关。

              【讨论】:

                【解决方案8】:

                在我的树莓派模型 3 上,RAM (1GB) 和交换空间 (1GB) 太小了。 将交换空间增加到 10GB 后,建议的命令“ng-high-memory”起作用了!

                【讨论】:

                  【解决方案9】:

                  这对我有用:

                  我已经更新到最新的 Angular,如下所示:ng update @angular/cli@^8 @angular/core@^8

                  然后

                  package.json

                  "scripts": {
                      "ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --configuration=prod",
                  }
                  

                  之后:

                  npm run ng-high-memory
                  

                  网址: JavaScript heap out of memory

                  【讨论】:

                  • 不仅在 Angular 8 中。我在 Angular 5 中也遇到了这个问题。我已将此命令添加到我的 package.json 中,并且工作正常。但不知道这种做法是否正确。
                  • @jpcmf80 是的,上述方法是干净且正确的方法。你可以看到上面的帖子,并得到谷歌核心团队成员的确认。
                  • @Sampath 我可以使用此命令成功构建,但在执行提交命令时它没有提交代码。面临以下错误:“ FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory”
                  • @Sampath 你能帮帮我吗...!
                  • @NaseerAttari 你有什么问题?
                  猜你喜欢
                  • 2021-10-20
                  • 2021-05-06
                  • 2020-08-22
                  • 2020-03-12
                  • 2019-07-15
                  • 1970-01-01
                  • 1970-01-01
                  • 2022-10-06
                  • 2020-09-11
                  相关资源
                  最近更新 更多