Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

npm and yarn are many times slower in WSL than on plain Windows

Errornpm install takes minutes in WSL but seconds in PowerShell

Short answer

Almost always the project lives on the Windows drive (/mnt/c), and every file read crosses between the two systems. Microsoft recommends keeping Linux-side projects in the Linux file system. The second cause is a Windows copy of Node or npm found first on the PATH. Check both with pwd and which.

  • Applies to WSL 2, Ubuntu 24.04 on WSL, Windows 11, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the folder you work in, and the path of the npm that runs. A /mnt/ path in either one points at the cause.

    pwd
    which node npm
  2. 2Match what you see, then jump to its fix

    1. 1pwd starts with /mnt/c or /mnt/dThe project is stored on the Windows drive, mounted under /mnt/cFix
    2. 2which npm prints a path under /mnt/c/Program Files/nodejsnpm or node resolves to the Windows installation through the PATHFix

What does the error look like?

  • npm install takes minutes in WSL but seconds in PowerShell
  • pwd prints /mnt/c/Users/...

Cause 1 of 2

The project is stored on the Windows drive, mounted under /mnt/c

1Check

Microsoft states that for the fastest performance you should store files in the WSL file system when you work from a Linux command line, and that a mounted drive is slower.

pwd
df -T . | tail -1

2Fix

Move the project into your Linux home folder and work from there. Open it in Windows Explorer with explorer.exe when you need to.

mkdir -p ~/projects
cp -r /mnt/c/Users/<user name>/Project ~/projects/
cd ~/projects/Project
rm -rf node_modules && npm install
explorer.exe .

3Verify

pwd shows a /home path, and the install time drops.

pwd
time npm install

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 2

npm or node resolves to the Windows installation through the PATH

1Check

By default WSL adds the Windows PATH entries to the Linux PATH, so a Windows Node can win when no Linux Node is installed.

which -a node npm

2Fix

Install Node.js inside the distro (for example with your package manager or a version manager), or stop WSL from appending the Windows PATH. Set it in /etc/wsl.conf, then restart WSL from PowerShell.

# /etc/wsl.conf
[interop]
appendWindowsPath = false

# PowerShell
wsl --shutdown

3Verify

which npm prints a Linux path.

which npm && node -v

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Create every Linux-side project under your home folder, never under /mnt.
  • Run tools from the same side as the files: Linux tools on Linux files, Windows tools on Windows files.
  • Open the folder in your editor through the WSL integration instead of copying files back to C:.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

nginx gives up waiting for the app and returns 504

upstream timed out (110: Connection timed out) while reading response header from upstream

nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.