接近堆限制分配Angular 8的无效标记紧凑-JavaScript堆内存不足

时间:2019-11-18 13:51:28

标签: node.js angular typescript

  

42%的建筑274/275模块1个活动   ... \ src \ index.js ??解压缩!D:\ Clients \ community.web.v2 \ node_modules \ sass-loader \ lib \ loader.js ?? ref--15-3!D:\ Clients \ Nalaka \ dc2vue.community.web.v2 \ src \ styles.scss   <---后几个GC --->

     

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

     

<--- JS堆栈跟踪--->

     

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

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

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

     

致命错误:接近堆限制分配的无效标记压缩   失败-JavaScript堆内存不足1:00007FF76C26DD8A   v8 :: internal :: GCIdleTimeHandler :: GCIdleTimeHandler + 4506 2:   00007FF76C248886节点:: MakeCallback + 4534 3:00007FF76C249200   node_module_register + 2032 4:00007FF76C5630DE   v8 :: internal :: FatalProcessOutOfMemory + 846 5:00007FF76C56300F   v8 :: internal :: FatalProcessOutOfMemory + 639 6:00007FF76C749804   v8 :: internal :: Heap :: MaxHeapGrowingFactor + 9620 7:00007FF76C7407E6   v8 :: internal :: ScavengeJob :: operator = + 24550 8:00007FF76C73EE3C   v8 :: internal :: ScavengeJob :: operator = + 17980 9:00007FF76C747B87   v8 :: internal :: Heap :: MaxHeapGrowingFactor + 2327 10:00007FF76C747C06   v8 :: internal :: Heap :: MaxHeapGrowingFactor + 2454 11:00007FF76C871EA7   v8 ::内部::工厂:: NewFillerObject + 55 12:00007FF76C8EF096   v8 :: internal :: operator << + 73494 13:00000257D3FDC5C1

我已经尝试过以下解决方案: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\community.web.v2
> > 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"

8 个答案:

答案 0 :(得分:6)

将节点js版本升级到 v12

答案 1 :(得分:2)

您分配的内存不足。

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

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 重命名为您想要的任何名称

答案 2 :(得分:0)

这对我有用:

我已经更新为最新的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

答案 3 :(得分:0)

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

答案 4 :(得分:0)

我在cmd上使用了以下命令,而不是解决package.json中的内存问题。这对我有用。

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

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

答案 5 :(得分:0)

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

原来是这样的...

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

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

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

答案 6 :(得分:0)

export NODE_OPTIONS=--max_old_space_size=8192

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

答案 7 :(得分:0)

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

// terminal
export NODE_OPTIONS=--max_old_space_size=8096

// Windows
set NODE_OPTIONS=--max_old_space_size=8096