node.js - 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
但它没有解决任何问题。
- 节点JS:v14.9.0
- NPM:v6.14.8
有什么建议吗?
解决方案
昨天我也遇到了同样的问题。不要尝试在 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”运行。添加流程管理器。
推荐阅读
- python - RDS MySQL 加载数据本地文件。错误 1148。此 MySQL 版本不允许使用的命令
- c# - 将 base64 字符串转换为字节数组失败,来自 iOS 的 base64 字符串 - “Base-64 字符数组或字符串的长度无效”
- pundit - railsapps (rails-devise-pundit) 应用程序是否支持多角色?
- php - 在 Eloquent ORM 中用不同的主键覆盖用户 ID 后,如何获取用户 ID?
- c# - 数据不保存在数据库的自定义表中,而是保存在模板数据库表中
- javascript - 在一种方法中调用 JQuery 的 html() 函数两次不起作用
- python - 试图通过一个错误“缺少 1 个必需的位置参数”使函数减去定义的数字
- php - 从不同的表数据更新表行不起作用
- json - 如何在 MVC Razor 中使用 ajax 创建单页搜索表单
- css - 在 svg 中插入 SCSS(sass) 变量以更改颜色