致命错误:在堆限制附近无效的标记压缩分配失败-离子 3 中的 JavaScript 堆内存不足

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53230823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:05:15  来源:igfitidea点击:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory in ionic 3

javascriptionic-frameworkionic3

提问by Himanshu Shekhar

When I run ionic 3 project using "ionic serve" command than getting this error:

当我使用“ionic serve”命令运行 ionic 3 项目时,出现此错误:

enter image description here

在此处输入图片说明

回答by Hakim CHRIFI ALAOUI

same issue on centos server 7, but this solved my problem:

centos server 7 上有同样的问题,但这解决了我的问题:

node --max-old-space-size=X node_modules/@angular/cli/bin/ng build --prod

Where X = (2048 or 4096 or 8192 o..)is the value of memory

X = (2048 or 4096 or 8192 o..)记忆的价值在哪里

回答by Germán Ayala

In my case, fix this problem installing NodeJs,version 12.10.0

在我的情况下,解决这个问题安装 NodeJs,版本 12.10.0

回答by Emmanuel N K

For a non-angular general answer for those who land on this question from Google:

对于那些从谷歌登陆这个问题的人的非角度一般答案:

Every time you face this error its probably because of a memory leak or difference between how Node <= 10 and Node > 10 manage memory. Usually just increasing the memory allocated to Node will allow your program to run but may not actually solve the real problemand the memory limit could be reached again. I'd advise profiling memory usage in your node process when it starts running or updating to node > 10.

每次遇到此错误时,可能是因为内存泄漏或 Node <= 10 和 Node > 10 管理内存的方式不同。通常只是增加分配给 Node 的内存将允许您的程序运行,但实际上可能无法解决真正的问题,并且可能会再次达到内存限制。我建议在节点进程开始运行或更新到节点 > 10 时分析它的内存使用情况。

I had a memory leak.

我有内存泄漏。

That said, to increase the memory, in the terminal where you run your Node process:

也就是说,要增加内存,请在运行 Node 进程的终端中:

export NODE_OPTIONS="--max-old-space-size=8192"

where values of max-old-space-sizecan be: [2048, 4096, 8192, 16384]etc

其中的值max-old-space-size可以是:[2048, 4096, 8192, 16384]

回答by runnerpaul

Try this solution which was pointed out in an old message on the forum: https://forum.ionicframework.com/t/3-7-0-ios-build-with-prod-not-working/107061/24

尝试在论坛上的旧消息中指出的此解决方案:https: //forum.ionicframework.com/t/3-7-0-ios-build-with-prod-not-working/107061/24

Open node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js

打开 node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js

Change the first line from:

将第一行从:

#!/usr/bin/env node

to

#!/usr/bin/env node --max-old-space-size=4096

Try values 1024 and 2048, but for a relatively large app you may need 4096.

尝试值 1024 和 2048,但对于相对较大的应用程序,您可能需要 4096。

回答by Sushrut Singh Sisodiya

I got the same error when I execute ng buildcommand in Visual Studio code. But I can build successfully when I execute same thing in Windows command line in following sequence.

ng build在 Visual Studio 代码中执行命令时遇到了同样的错误。但是当我按以下顺序在 Windows 命令行中执行相同的操作时,我可以成功构建。

Step 1.

第1步。

set NODE_OPTIONS=--max_old_space_size=4096

Step 2.

第2步。

ng build

回答by lockman

node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --baseHref=/baseUrl/ --prod=true

回答by heinels

I got the same error message when I execute following statements in Visual Studio code. But I can build successfully when I execute same thing in windows command line.

我在 Visual Studio 代码中执行以下语句时收到相同的错误消息。但是当我在 Windows 命令行中执行相同的事情时,我可以成功构建。

npm install -g increase-memory-limit
increase-memory-limit
set NODE_OPTIONS=--max_old_space_size=4096
ng build -c deploy --build-optimizer --aot --prod --sourceMap

回答by Sarath Mohandas

Replace the line

更换线路

"start": "ng serve -o --port 4300 --configuration=en"with

"start": "ng serve -o --port 4300 --configuration=en"

"start":?"node?--max_old_space_size=5096?node_modules/@angular/cli/bin/ng?serve?-o?--port?4300?--configuration=en"

"start":?"node?--max_old_space_size=5096?node_modules/@angular/cli/bin/ng?serve?-o?--port?4300?--configuration=en"

NOTE:

笔记:

  1. port--4300 is not constant depends upon which port you selects.

  2. --max_old_space_size=5096 too not constant; any value 1024,2048,4096 etc

  1. 端口--4300 不是常数取决于您选择的端口。

  2. --max_old_space_size=5096 太不恒定;任何值 1024,2048,4096 等

回答by sambayour

For some reasons all the answer above didn't really work for me, I did the following to fix my issue:

由于某些原因,上面的所有答案对我都不起作用,我做了以下工作来解决我的问题:

  1. I had to first delete the node_modulesfolder
  2. re-install node.js on my PC and
  3. then npm install
  1. 我必须先删除node_modules文件夹
  2. 在我的 PC 上重新安装 node.js 和
  3. 然后 npm install

回答by Rust

In my case it was a recursionthat was causing react to use up all memory.

在我的情况下,这是导致反应耗尽所有内存的递归

This happened when I was refactoring my code and didn't notice this.

这发生在我重构我的代码并且没有注意到这一点时。

const SumComponent = () => {
  return (
    <>
      <SumComponent />
    </>
  ) 
}

In other node apps this might look like:

在其他节点应用程序中,这可能如下所示:

const someFunction = () => {
  ...
  someFunction(); 
  ...
}