Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install hangs forever in EC2

Trying to deploy a react app on AWS EC2. I'm using apache so I got git clone under /var/www/html.

I didn't have any problem when I deployed other projects, but when I npm install in this new project folder, within some seconds (when it's installing webpack), it just stuck at the same point with the same message. enter image description here

It stuck there forever and any other command doesn't work. So I have to force quit the terminal. After that, I can't connect on my EC2 instance for 10 - 20min.

I tried npm install --verbose, removing package-lock.json, npm config set registry http://registry.npmjs.org/ --global, npm cache verify ... nothing worked.

It's really frustrating. I don't know what should I do. Any advice will be appreciated.

like image 345
user13670138 Avatar asked Dec 06 '25 04:12

user13670138


2 Answers

In my case, i had to create a swap file on my micro ec2 instance. My npm install hanged and was killed eventually. Once i increased the memory with the swap file, all worked fine!

Commands i used:

sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap  /swapfile
sudo swapon /swapfile
sudo swapon  --show
sudo free -h

To make the swapfile persistent across reboots (run as root):

sudo echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
like image 165
Daniel Miranda Avatar answered Dec 11 '25 03:12

Daniel Miranda


What type of EC2 instance are you using? check monitoring data, cpu usage and memory consumption in my experience, "npm install" hangs easily on an EC2 micro instance, if you have a lot of dependencies.

like image 40
Ayoub Gharbi Avatar answered Dec 11 '25 01:12

Ayoub Gharbi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!