当我使用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
其他回答
当我在Visual Studio代码中执行ng build命令时,我得到了相同的错误。但是,当我按照以下顺序在Windows命令行上执行相同的操作时,我可以成功地构建。
步骤1。
set NODE_OPTIONS=--max_old_space_size=4096
步骤2。
ng build
更换线路
"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等
如果你在Windows上开发,在发布时遇到这个问题,请通过官方网站升级Node.js。
每更新一个Node.js版本,内存使用处理都会增加,尽管我没有找到确切的增加数字。
这是唯一对我有效的解决办法。我花了整整一个周末甚至更长的时间才解决这个问题。
在项目文件夹中运行此命令。使用服务而不是构建
node --max_old_space_size=8000 node_modules/@angular/cli/bin/ng serve --prod --port=4202
#!在ionic-app-scripts.js文件中的/usr/bin/env node——max-old-space-size=4096不能正常工作。
修改node_modules /。bin / ionic-app-scripts。CMD
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\@ionic\app-scripts\bin\ionic-app-scripts.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=4096 "%~dp0\..\@ionic\app-scripts\bin\ionic-app-scripts.js" %*
)
最后工作。