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


当前回答

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

步骤1。

set NODE_OPTIONS=--max_old_space_size=4096

步骤2。

ng build

其他回答

在我的例子中,它是一个递归,导致React用完所有内存。

这发生在我重构代码时,我没有注意到这一点。

const SumComponent = () => {
  return (
    <>
      <SumComponent />
    </>
  )
}

在其他Node.js应用程序中,这可能是这样的:

const someFunction = () => {
  ...
  someFunction();
  ...
}
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --baseHref=/baseUrl/ --prod=true

对我来说,当我在React项目中使用一个大的构建目录运行ESLint和Prettier时遇到了这个问题。取出后,一切都正常了。

我想这是因为在构建目录中有太多的文件。

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

我在Angular上也遇到了同样的问题。然后我写了

"serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve"

要打包的脚本。Json脚本,为我解决了这个问题。

并运行project this命令:

npm run serve