Skip to content

wsl is freeze on installing packages by npm install #11670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
haw0k opened this issue Jun 8, 2024 · 11 comments
Closed
1 of 2 tasks

wsl is freeze on installing packages by npm install #11670

haw0k opened this issue Jun 8, 2024 · 11 comments

Comments

@haw0k
Copy link

haw0k commented Jun 8, 2024

Windows Version

Microsoft Windows [Version 10.0.22631.3593]

WSL Version

2.1.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.146.1-2

Distro Version

Ubuntu 22.04.3 LTS

Other Software

NodeJS v20.14.0

Repro Steps

  1. Open Ubuntu 22.04.3 LTS terminal
  2. cd some_project_with_package.json
  3. npm install

Expected Behavior

The terminal continuously displays the package installation process.

### Tasks
- [ ] Add a draft title or issue reference here

Actual Behavior

WSL terminal freezes.
The npm process won't exit by the Ctrl+C command.

$ rm -rf node_modules/
$ npm i
⠏^C^C

The npm process exists.

$ ps axl | grep npm
0  1000     658     375  20   0 3315272 2128964 x64_sy Sl+ pts/0    0:56 npm i

Diagnostic Logs

No response

### Tasks
Copy link

github-actions bot commented Jun 8, 2024

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to wsl-gh-logs@microsoft.com with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@haw0k
Copy link
Author

haw0k commented Jun 8, 2024

Copy link

github-actions bot commented Jun 8, 2024

Diagnostic information
Detected appx version: 2.1.5.0

@OneBlue
Copy link
Collaborator

OneBlue commented Jun 11, 2024

Thank you @haw0k . Can you share an strace of the process that freezes ? (strace -f )

@KyryloSWAN
Copy link

KyryloSWAN commented Jun 13, 2024

$ npm cache clean --force
$ rm -rf node_modules/ package-lock.json
$ npm i
$ ps ax | grep npm
$ strace -f -p 56172 -o strace.log

Best environment for reproducing: The nextjs empty project created by npx create-next-app@latest
strace.zip

Copy link
Contributor

This issue has been automatically closed since it has not had any author activity for the past 7 days. If you're still experiencing this issue please re-file it as a new issue.

Thank you!

@h3rmanj
Copy link

h3rmanj commented Nov 4, 2024

Did any of you manage to fix this? I'm getting this now, and it only happens if there is no package-lock.json already, so it freezes for all new projects.

@KyryloSWAN
Copy link

Newest versions, same buggy behavior.

> wsl --version
WSL version: 2.3.24.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.65
MSRDC version: 1.2.5620
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.22631.4317

@h3rmanj
Copy link

h3rmanj commented Nov 5, 2024

Today it worked again. Updated to latest wsl by manually downloading from releases, and installed node and npm with volta. No idea what fixed it, seems a little random.

> node --version
v22.11.0

> npm --version
10.9.0

> wsl --version
WSL version: 2.3.24.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.65
MSRDC version: 1.2.5620
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.22631.4317

@Jikodis
Copy link

Jikodis commented Dec 10, 2024

This is perhaps related to these two issues which seem to be resolved with releases in npm with version 10.9.1.

npm/cli#7868
npm/cli#7814

I was using nvm in WSL to manage my node version. After selecting my node version through nvm I ran npm install -g npm. This allowed my node to use npm v10.9.2. I had no hanging npm installs after that.

@alexhail
Copy link

alexhail commented May 4, 2025

Hey all, this really stumped me and I was googling for hours, found the post about network resolve configuration changes for wsl but it didn't work for me. The root issue ended up being that I needed to reconfigure npm to use the WSL bash shell for running scripts instead of Windows cmd.exe. This can sometimes require installing Node.js from within WSL itself from what I can tell.

Simple script to take care of this for you on a clean WSL Ubuntu distro that:

  1. Checks for Node.js and npm in WSL - If they're not installed, it installs them using apt
  2. Configures npm to use WSL bash - This is the critical fix, setting npm to use /usr/bin/bash instead of Windows CMD
  3. Sets up a proper npm global path - Configures npm to use a local directory (in WSL) for global packages
  4. Updates PATH in .bashrc - Ensures global npm packages are accessible
  5. Reloads the bash configuration - Applies the PATH changes
  6. Verifies the settings and shows the current npm configuration so you can confirm it worked

(Note: I did have to run wsl --shutdown afterwards to get npm install to work again)

#!/bin/bash
set -e

echo "Fixing npm install issues in WSL..."

# Step 1: Make sure Node.js and npm are installed in WSL
echo "Checking for Node.js and npm in WSL..."
if ! command -v node &> /dev/null || ! command -v npm &> /dev/null; then
    echo "Installing Node.js and npm in WSL..."
    sudo apt update
    sudo apt install -y nodejs npm
    echo "Node.js and npm installed successfully."
else
    echo "Node.js and npm are already installed in WSL."
    echo "Node.js version: $(node -v)"
    echo "npm version: $(npm -v)"
fi

# Step 2: Configure npm to use WSL bash for scripts
echo "Configuring npm to use WSL bash for scripts..."
npm config set script-shell /usr/bin/bash

# Step 3: Set npm to use local (WSL) node for installations
echo "Configuring npm to use local paths..."
npm config set prefix ~/.npm-global
mkdir -p ~/.npm-global/bin

# Step 4: Add npm global bin to PATH if not already there
if ! grep -q "npm-global/bin" ~/.bashrc; then
    echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
    echo "Added npm-global/bin to PATH in ~/.bashrc"
fi

# Step 5: Reload bash configuration
source ~/.bashrc

# Step 6: Verify settings
echo "Current npm configuration:"
npm config get script-shell
npm config get prefix

echo ""
echo "Fix completed! Try running 'npm install' in your project directory now."
echo "If you're still experiencing issues, try opening a new WSL terminal or restart WSL with:"
echo "wsl --shutdown"
echo ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants