首页 > 解决方案 > AWS EC2 上的 JavaScript 堆内存不足

问题描述

我正在使用具有 t2.micro 类型的 AWS EC2 实例,并且我正在尝试通过使用tsc命令构建使用 typescript 的 REST API,但我遇到了内存问题。

Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

我尝试使用,--max_old_space_size-1024但它没有解决任何问题。

有什么建议吗?

标签: node.jstypescriptamazon-ec2build

解决方案


昨天我也遇到了同样的问题。不要尝试在 ec2 实例中构建 REST API。您可以在本地构建它,您可以将构建文件(index.js)和 package.json 放入 ec2。试用这篇文章。https://auth0.com/blog/use-typescript-to-create-a-secure-api-with-nodejs-and-express-getting-started/。然后安装 node.js https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-up-node-on-ec2-instance.html。然后通过“npm install”安装依赖项并运行构建文件。在我的情况下,“node index.js”运行。添加流程管理器。


推荐阅读