JavaScript heap out of memory on AWS EC2

Viewed 4309

I'm using an AWS EC2 instance with a t2.micro type and I'm trying to build my REST API that uses typescript by using the tsc command but I'm getting a memory issue.

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

I tried to use the --max_old_space_size-1024 but it fixed nothing.

  • NodeJS: v14.9.0
  • NPM: v6.14.8

Any suggestions guys?

1 Answers

Yesterday I also faced the same problem. Don't try to build REST API in ec2 instance. You can build it in your local and you can put build file(index.js) and package.json into ec2. Tryout this article. https://auth0.com/blog/use-typescript-to-create-a-secure-api-with-nodejs-and-express-getting-started/. Then install node.js https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-up-node-on-ec2-instance.html . Then install the dependencies by "npm install" and run the build file. In my case "node index.js" make runs. Add Process manager.

Related