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


当前回答

添加参数——build-optimizer解决了我的问题:

Node——max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build——prod——构建优化器

我不知道为什么添加only——build-optimizer可以解决这个问题,但根据Angular文档,它应该在启用AOT编译的情况下使用,所以更新后的命令应该如下所示:

--build-optimizer=true --aot=true

Angular构建文档

其他回答

#!在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" %*
)

最后工作。

在我的案例中,我通过安装Node.js 12.10.0版本解决了这个问题。

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

我删除了现有的Node.js模块,并运行以下命令来解决我的问题:

npm install -all
npm audit fix

在项目文件夹中运行此命令。使用服务而不是构建

node --max_old_space_size=8000 node_modules/@angular/cli/bin/ng serve  --prod --port=4202