当我使用Ionic serve命令运行Ionic 3项目时,我会得到这个错误:


当前回答

只需在终端中输入以下内容:

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

当超过Node.js允许的默认最大内存时,就会发生错误。所有这些操作都增加了允许的最大内存。

其他回答

我在CentOS服务器7上也有同样的问题,但这解决了我的问题:

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

其中X =(2048或4096或8192 o..)是内存的值。

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

在我的例子中,错误是由于在for中不恰当地使用条件引起的。循环。而不是:

for (let t = startNo; t <= endNo; t++) {}

我有:

for (let t = startNo; endNo; t++) {}

我没有使用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

这个问题在我为我的项目更新了我的所有库,如Node.js, TypeScript, Yarn, npm等之后就消失了。