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


当前回答

更换线路

"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等

其他回答

试试这个解决方案,在论坛上的一个旧消息中指出:3.7.0:iOS build with——prod无法工作

打开node_modules / @ionic / app-scripts / bin / ionic-app-scripts.js

将第一行改为:

#!/usr/bin/env node

to

#!/usr/bin/env node --max-old-space-size=4096

尝试1024和2048的值,但对于一个相对较大的应用程序,你可能需要4096。

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

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

我有:

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

执行如下命令:

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

更换线路

"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等

另一个非angular的答案(我在AWS Amplify上构建React应用时也遇到了同样的问题)。

正如Emmanuel所提到的,这似乎来自Node.js v10和Node.js v12处理内存的方式的差异。

我试着增加记忆,但没有用。但是使用Node.js v12做到了。

根据richard的解释,检查如何将nvm use $VERSION_NODE_12添加到构建设置中

前端: 阶段: preBuild: 命令: - nvm使用$VERSION_NODE_12 - NPM ci 构建: 命令: - nvm使用$VERSION_NODE_12 - node -v - NPM运行脚本构建