Vscode 未启动且无法连接到 WSL

Vscode does not start and cannot connect to WSL

我在 Ubuntu WSL 中使用 vscode,几个小时前它工作正常,但在我开始编写 js 时突然停止工作。

我已尝试删除并重新安装 vscode,但这不起作用,并且在我尝试清除时出现错误:无法找到包代码

远程连接vscode到wsl时出现错误如下:

 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

这是来自 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

您可能需要重新设置 WSL 或升级到 WSL2。这是一个有用的 link: https://docs.microsoft.com/en-us/windows/wsl/install-win10

或者试试这个 link: https://code.visualstudio.com/docs/remote/wsl-tutorial#:~:text=运行%20Terminal%20%3E%20New%20Terminal%20(Ctrl,VS%20Code%20运行%20on%20Windows。 它主要用于 vscode 上的 运行 Python,但如果您按照 'Intergrated Terminal' 步骤进行操作,它可能会起作用。

也许比接受的答案更简单,我能够通过以下方式解决问题:

  1. 开始 vscode 在 Windows
  2. 更新 remote-wsl 扩展程序
  3. 关闭vscode
  4. 打开 WSL
  5. 从 WSL
  6. 开始 vscode