当我使用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等

其他回答

当我运行angular 'ng serve'时,我也有类似的问题:

"致命错误:无效的标记-压缩接近堆限制分配失败- JavaScript堆内存不足"

在我的例子中,我发现我的Angular应用程序使用了惰性加载。一个模块已经导入到自己的路由模块,但有人做了一个导入它到应用程序模块,这导致递归(?)加载。

这会导致内存不足。

对我来说,这就像模块导入自己一样愚蠢:

// worker.js
import { worker } from './worker'

对我来说,这是一个Firebase包的问题。

在你的包中只添加"@firebase/database": "0.2.1"。json文件。重新安装node_modules,它就可以工作了。

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

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

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

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

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