I am running in to the same issue, I have a t4g.small (2 vCPU & 2GB RAM), I have added 1GB or swap and it is still hanging.
I have run the same NPM install on smaller instances, not on AWS, and they run absolutely fine.