当我使用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
其他回答
我使用的是Node.js v-14.17的最新稳定版本。我在新的Angular Ionic项目中也遇到了同样的问题,尝试了之前的大多数答案都没有成功。
最终在升级到Node.js 16.4.2 LTS后,修复了这个问题。
如果在Visual Studio Code中运行React应用程序时发生了这种情况,请检查您的propTypes,未定义的propTypes会导致同样的问题。
当我运行angular 'ng serve'时,我也有类似的问题:
"致命错误:无效的标记-压缩接近堆限制分配失败- JavaScript堆内存不足"
在我的例子中,我发现我的Angular应用程序使用了惰性加载。一个模块已经导入到自己的路由模块,但有人做了一个导入它到应用程序模块,这导致递归(?)加载。
这会导致内存不足。
我没有使用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
更换线路
"start": "ng serve -o——port 4300——configuration= zh " with
"start": "node——max_old_space_size=5096 node_modules/@angular/cli/bin/ng serve -o——port 4300——configuration= zh "
注意:
端口—4300不是常量,这取决于您选择的端口。 ——max_old_space_size=5096 too not constant;任意值1024、2048、4096等