NPM 8.5.0 is broken with WSL2 Ubuntu 20.02

Well this one is baffling. I’ve got a new laptop and I’m trying to install Expo, a javascript React Native framework. After getting the LTS version of Node with NVM (Node Version Manager) – I found that the default Expo install command would freeze after a few seconds. Running it verbose offered little extra information. I tried uninstalling, clearing caches, ect. all to no avail.

The solution was found on a Reddit post down in the comments. Apparently, there’s some kind of issue happening in the DNS resolver.

Run the following commands in WSL. Substitute 8.8.8.8 with a DNS resolver of your choice.

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

Then run the following command in a prompt with admin privilege

wsl --shutdown

No guarantee this won’t cause other issues down the road, but it solved my NPM install problem.

Leave a Comment