npm and yarn are many times slower in WSL than on plain Windows
npm install takes minutes in WSL but seconds in PowerShellShort 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.
Fix it fast
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 npm2Match what you see, then jump to its fix
What does the error look like?
npm install takes minutes in WSL but seconds in PowerShellpwd 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 -12Fix
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 installConfirmed by learn.microsoft.com
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 npm2Fix
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 --shutdown3Verify
which npm prints a Linux path.
which npm && node -vConfirmed by learn.microsoft.com
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
Azure App Service on Linux restarts the container and the site never starts
The container restarts again and again and the site returns an application error
App Service sends a warmup request to the container and restarts it if no HTTP answer comes back in time.
5 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A native Node.js module fails on AWS Lambda with invalid ELF header
Error: /var/task/node_modules/<package>/build/Release/<name>.node: invalid ELF header
Lambda loads native addons on Linux, so a .node file built on macOS or Windows is not a valid Linux ELF file there.
3 causes, each with a fixServers
nginx 502 Bad Gateway in front of a Node.js app
connect() failed (111: Connection refused) while connecting to upstream
A 502 means nginx reached for your Node.js app and got nothing usable back.
5 causes, each with a fixServers
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 fixServers
Pages load unstyled because /_next/static files return 404 behind nginx
GET https://example.com/_next/static/chunks/main.js 404 (Not Found)
The browser asks for /_next/static/..
3 causes, each with a fix