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


当前回答

请检查你的Node.js版本:

节点- v

如果是10.1.1,那么你需要通过下面的命令更新你的根Node.js版本:

Curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash ~ / .nvm / nvm.sh来源 nvm ls NVM安装12.18.1

完成后,请重新启动终端或Visual Studio。

它可以工作100美元。

对于Ionic用户,请在package.json中添加以下代码

“ionic:build”:“node——max-old-space-size=16384 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build”,

其他回答

当我在Visual Studio代码中执行ng build命令时,我得到了相同的错误。但是,当我按照以下顺序在Windows命令行上执行相同的操作时,我可以成功地构建。

步骤1。

set NODE_OPTIONS=--max_old_space_size=4096

步骤2。

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

执行如下命令:

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

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

只需执行以下命令:

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