Vscode does not start and cannot connect to WSL

29.5k views Asked by At

I'm using vscode in Ubuntu WSL, it was working fine a couple of hours ago and suddenly stopped working as I started writing js.

I have tried deleting and reinstalling vscode but that does not work and an error : Unable to locate package code appears when I try to purge.

When connecting vscode to wsl remotely error appears as follows:

 2020-09-30 09:20:11.585] Resolving wsl+Ubuntu, resolveAttempt: 1
[2020-09-30 09:20:11.625] Starting VS Code Server inside WSL (Ubuntu)
[2020-09-30 09:20:11.625] Extension version: 0.44.5, Windows build: 19041. Multi distro support: available. WSL path support: enabled
[2020-09-30 09:20:11.756] Probing if server is already installed: C:\WINDOWS\System32\wsl.exe -d Ubuntu -e sh -c "[ -d ~/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3d05f9a6883a ] && printf found || ([ -f /etc/alpine-release ] && printf alpine-; uname -m)"
[2020-09-30 09:20:11.886] Probing result: found
[2020-09-30 09:20:11.886] Server install found in WSL
[2020-09-30 09:20:11.887] Launching C:\WINDOWS\System32\wsl.exe -d Ubuntu sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" e5e9e69aed6e1984f7499b7af85b3d05f9a6883a stable .vscode-server 0  ' in c:\Users\divya\.vscode\extensions\ms-vscode-remote.remote-wsl-0.44.5}
[2020-09-30 09:20:11.996] Setting up server environment: Looking for /home/dgoel/.vscode-server/server-env-setup. Not found.
[2020-09-30 09:20:11.996] WSL version: 4.4.0-19041-Microsoft Ubuntu
[2020-09-30 09:20:11.996] Starting server: /home/dgoel/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3d05f9a6883a/server.sh  --port=0 --use-host-proxy --fileWatcherPolling=0 
[2020-09-30 09:20:11.996] /mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts/wslServer.sh: 63: /home/dgoel/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3d05f9a6883a/server.sh: not found
[2020-09-30 09:20:11.997] VS Code Server for WSL closed unexpectedly.
[2020-09-30 09:20:11.997] For help with startup problems, go to
[2020-09-30 09:20:11.997] https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips

here's the debug report from wsl ubuntu:

VSCODE_WSL_DEBUG_INFO=true code .
+ COMMIT=e5e9e69aed6e1984f7499b7af85b3d05f9a6883a
+ APP_NAME=code
+ QUALITY=stable
+ NAME=Code
+ DATAFOLDER=.vscode
+ realpath /mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/bin/code
+ dirname /mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/bin/code
+ dirname /mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/bin
+ VSCODE_PATH=/mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code
+ ELECTRON=/mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/Code.exe
+ IN_WSL=false
+ [ -n Ubuntu ]
+ IN_WSL=true
+ [ true = true ]
+ export WSLENV=ELECTRON_RUN_AS_NODE/w:
+ wslpath -m /mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js
+ CLI=C:/Users/divya/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js
+ WSL_EXT_ID=ms-vscode-remote.remote-wsl
+ ELECTRON_RUN_AS_NODE=1 /mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/Code.exe C:/Users/divya/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js --locate-extension ms-vscode-remote.remote-wsl
+ cat /tmp/remote-wsl-loc.txt
+ WSL_EXT_WLOC=c:\Users\divya\.vscode\extensions\ms-vscode-remote.remote-wsl-0.44.5
+ [ -n c:\Users\divya\.vscode\extensions\ms-vscode-remote.remote-wsl-0.44.5 ]
+ wslpath -u c:\Users\divya\.vscode\extensions\ms-vscode-remote.remote-wsl-0.44.5
+ WSL_CODE=/mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts/wslCode.sh
+ /mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts/wslCode.sh e5e9e69aed6e1984f7499b7af85b3d05f9a6883a stable /mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/Code.exe code .vscode .
+ [ -z .vscode ]
+ echo .vscode
+ sed -e s/.vscode/.vscode-server/g
+ DATAFOLDER=.vscode-server
+ VSCODE_REMOTE_BIN=/home/dgoel/.vscode-server/bin
+ AUTHORITY=wsl+default
+ [ Ubuntu ]
+ AUTHORITY=wsl+Ubuntu
+ [ ! -d /home/dgoel/.vscode-server ]
+ dirname /mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts/wslCode.sh
+ /mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts/wslDownload.sh e5e9e69aed6e1984f7499b7af85b3d05f9a6883a stable /home/dgoel/.vscode-server/bin
+ [ ! -d /home/dgoel/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3d05f9a6883a ]
+ RC=0
+ [ 0 -ne 0 ]
+ dirname /mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts/wslCode.sh
+ VSCODE_CLIENT_COMMAND=/mnt/c/Users/divya/AppData/Local/Programs/Microsoft VS Code/Code.exe VSCODE_CLIENT_COMMAND_CWD=/mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts VSCODE_CLI_AUTHORITY=wsl+Ubuntu /home/dgoel/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3d05f9a6883a/bin/code .
/mnt/c/Users/divya/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.5/scripts/wslCode.sh: 53: /home/dgoel/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3d05f9a6883a/bin/code: not found
+ exit 127
9

There are 9 answers

3
No_Name On BEST ANSWER

You might need to set up your WSL again or upgrade to WSL2. Here is a helpful link: https://learn.microsoft.com/en-us/windows/wsl/install-win10

Or try this link: https://code.visualstudio.com/docs/remote/wsl-tutorial#:~:text=Run%20Terminal%20%3E%20New%20Terminal%20(Ctrl,VS%20Code%20running%20on%20Windows. It's mostly for running Python on vscode, but it might work if you follow the 'Intergrated Terminal' steps.

2
Enrico Sanguin On

Maybe more simple than the accepted answer, I was able to solve the issue by:

  1. start vscode in Windows
  2. update the remote-wsl extension
  3. close vscode
  4. open WSL
  5. start vscode from WSL
0
Buddy On

I just got the same issue when i Updated VS code from the GUI. After that I couldn't start it from WSL2.

What fixed it for me was to also update VS code from WSL.

sudo apt update

sudo apt upgrade

I suspect that something broke because I updated VS Code through the VS code GUI instead of through apt.

1
Anurag Tiwari On

This worked for me-- Follow this link: https://code.visualstudio.com/docs/remote/wsl-tutorial Skip the Python development part if you don't want it then go to the Run in WSL part and run: 'code .' to install the VS code server.

Then open VS Code and choose new WSL window select your folder.

1
Joram On

I had a similar issue after updating VSCode, I guess. When I reinstalled the remote-wsl extension & restarted VSCode, the problem was still existing.

Afterwards I did the following:

  • restarting the WSL by executing wsl --shutdown inside a windows command line (PowerShell or Command Prompt)
  • opening ubuntu again (I also did sudo apt update and sudo apt upgrade at this point)
  • navigating to the project folder and opening VSCode from there (code .)

This might be related: VS Code connect to WSL Ubuntu 20.04 LTS, fail with error: Could not fetch remote environment

1
Bruce HU On

This command works for me

netsh winsock reset
0
TrojanName On

What worked for me was even simpler:

I closed WSL session and from Powershell, I did

wsl --shutdown

Restarted WSL and now Code works fine.

0
Zagaz On

In my case, I solved it just making a rollback of the previews version (Image below). Also do a:

sudo apt update
sudo apt upgrade

enter image description here

0
Santi On

First try should be update WSL, I do not know why is not listed here.

Run in a powershell:

wsl --update

I also tried:

  • Uninstall last Win11 updates (did not work)
  • Choose a previous VSCode WSL plugin version (did not work)
  • Updating the Debian distro (did not work)
  • Unregister and install the distro (after wsl --update) (WORKS...but IMO was the wsl update what make it work)