TS build fails on AWS EC2 t2.micro due to memory limits - how to fix?

I’m deploying a TypeScript project to an AWS EC2 t2.micro instance (1GB RAM). While the build works fine locally, it fails on the EC2 instance with memory related crashes.

During npm run build (which runs tsc), the process gets killed… :smiling_face_with_tear:

What I’ve Tried

  1. Added 2GB swap space (helped slightly but still fails on larger builds).
  2. Reduced TypeScript’s memory usage with tsc --incremental.
  3. Already using Node.js 18+ for better memory management.

Is there a way to split the build process into smaller chunks? If possible?? or are there optimized tsconfig.json settings for low-memory environments.

Please let me know…