当我使用Ionic serve命令运行Ionic 3项目时,我会得到这个错误:
当前回答
执行如下命令:
export NODE_OPTIONS="--max-old-space-size=2048"
检查你已经有多少钱了:
> node
> v8.getHeapStatistics()
{
total_heap_size: 6049792,
total_heap_size_executable: 524288,
total_physical_size: 5477720,
total_available_size: 1094444024,
used_heap_size: 4141728,
heap_size_limit: 1098907648,
malloced_memory: 8192,
peak_malloced_memory: 582752,
does_zap_garbage: 0,
number_of_native_contexts: 2,
number_of_detached_contexts: 0
}
然后heap_size_limit: 1098907648
其他回答
在我的例子中,它是一个递归,导致React用完所有内存。
这发生在我重构代码时,我没有注意到这一点。
const SumComponent = () => {
return (
<>
<SumComponent />
</>
)
}
在其他Node.js应用程序中,这可能是这样的:
const someFunction = () => {
...
someFunction();
...
}
我没有使用ng build,而是在终端中执行以下命令来修复这个问题。
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod
那就发球吧。
这就是我的终端机
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\ProjectPath\Project1> node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod
我在CentOS服务器7上也有同样的问题,但这解决了我的问题:
node --max-old-space-size=X node_modules/@angular/cli/bin/ng build --prod
其中X =(2048或4096或8192 o..)是内存的值。
对我来说,当我在React项目中使用一个大的构建目录运行ESLint和Prettier时遇到了这个问题。取出后,一切都正常了。
我想这是因为在构建目录中有太多的文件。
对于我来说,我得到了这个错误,因为我失去了对我的angular中dist文件夹设置的输出路径的访问。json文件。在我用更新的凭证重新连接到远程路径后,错误消失了。