Opening WSL remote window not working - command wslpath not found - visual-studio-code

When trying to open a new Remote-WSL window I run into an error during the "Installing VS Code Server in WSL (details): Installing WSL components" step. Appears it can not find the wslpath command.
I have tried looking at my PATH variables, I didn't see wslpath anywhere there nor do I know what the path should look like? I also tried reinstalling my linux distribution but that did not help.
[2019-07-09 12:23:39.266] Launching C:\Windows\System32\wsl.exe bash -c "'$(wslpath -u 'c:/Users/laida/.vscode/extensions/ms-vscode-remote.remote-wsl-0.38.8/scripts/wslServer.sh')' '0f3794b38477eea13fb47fbe15a42798e6129338' 'stable' '.vscode-server' 'C:/Users/laida/AppData/Local/Temp/vscode-remote-wsl/0f3794b38477eea13fb47fbe15a42798e6129338/vscode-server-linux-x64.tar.gz' 0 " in c:\Users\laida\.vscode\extensions\ms-vscode-remote.remote-wsl-0.38.8
[2019-07-09 12:23:39.562] /bin/bash: wslpath: command not found
[2019-07-09 12:23:39.562] bash: : command not found
[2019-07-09 12:25:10.024] VS Code Server for WSL failed to start. No messages received for 90s

I just ran into this today when starting up Remote - WSL. I am using an older Windows 10 version as #Biswapriyo noted, so I resolved it by installing wslpath from https://github.com/laurent22/wslpath
(Note: I also had to install php for that to work).
After that I was able to start Remote - WSL
I imagine that installing a newer Windows 10 version would probably work as well, but I'm unable to do that (managed image) and even if I were able that's kind of like killing an ant with a sledgehammer.

Related

Multiple Errors when Running Bun via WSL

I am trying to install some packages using Bun, but I am running into trouble:
$ bun install
error: Failed to initialize network thread: SystemOutdated.
HTTP requests will not work. Please file an issue and run strace().
Is there any known fix to this problem?
Bun leverages some network features which are only available on newer versions of WSL. You can usually fix these issues by updating your WSL version:
wsl --update
And restart your WSL VM:
wsl --shutdown
Also note that Bun only supports WSL2, so you would need to upgrade your WSL version to 2. See the Microsoft guide on updating from WSL1 to WSL2.
Furthermore, if you are getting an error for NotSameFileSystem, then you need to defer to using a different style for installations. This can be done by adding the --backend=copyfile to the end of your commands.

WSL2 VSCode Will Not Load After Ubuntu upgrade - Worked fine for 1 year

Running Windows 11, WSL2, Ubuntu 20.04. Been developing with VSCode over a year. I regularly run apt update and apt upgrade without any problem. Today after running apt upgrade I can no longer open VSCode. I get the following error
node:internal/modules/cjs/loader:990
throw err;
^
Error: Cannot find module '\wsl.localhost\Ubuntu-20.04\mnt\c\Users\JimD\AppData\Local\Programs\Microsoft VS Code\Code.exe'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
at Module._load (node:internal/modules/cjs/loader:832:27)
at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
That is the correct path to the VSCode exe, but I am not sure about the \wsl.localhost\Ubuntu-20.04 part
I rolled back my wsl to an month old backup and confirmed VSCode ran fine. Ran apt update and upgrade on that and get the same error.
Does anyone know how to fix this?
Starting from a functioning backup of the WSL image, I manually installed each packaged listed from apt list --upgradable. Turns out it is the upgrade from systemd-genie 2.3 to 2.4 that is causing the problem.
If I upgrade every other package, VSCode still loads. When I upgrade systemd-genie to 2.4 and restart my laptop, VSCode will not load giving the error in the original post.
edit /usr/lib/binfmt.d/WSLInterop.conf, change flag PF to F, reboot wsl seems able to let you run code again, but not sure whether any other side-effects exists.
My final solution was to just not use systemd. With the release of Windows 11, a new feature has been added to WSL to runs scripts on WSL startup. This feature is now also available to Windows 10 users if you install WSL from the Microsoft Store (requires KB5020030, which should be available under Optional Updates).
create the file /etc/wsl.conf and the following
[boot]
command = bash /etc/[path to startup script]
in my case I used the path "/etc/wsl-services-start.sh" This shell script contains only
service apache2 start
service mysql start
Starting apache2 and mysql was the only thing I needed systemd for, so this works fine for me.

Can't run CS50 command in VisualStudio code Terminal

Commands of CS50 are no more working anymore. I tried to redo steps of configuring SSH following the link https://cs50.readthedocs.io/github/#ssh , but I'm facing the message error present in the image below : CS50 command image error
After checking the documentation you provided and assuming it's what you followed,
https://cs50.readthedocs.io/projects/check50/en/latest/ states "Under Windows, please install the Linux subsystem. Then install check50 within the subsystem."
But in your picture you are using PowerShell (PS) so you can either start wsl from it by using the command wsl or you can open a new terminal from the vscode gui but make sure you selected wsl this time !

"Unable to resolve your shell environment"

On macOS Big Sur, I installed MacPorts and installed bash using it. I set my default shell to the MacPorts version of bash /opt/local/bin/bash by using chsh.
All was well.
I decided I would rather use Homebrew. I uninstalled MacPorts, installed Homebrew, installed bash via homebrew, and set my default shell to /opt/homebrew/bin/bash via chsh.
All was well, except when I am first starting vscode (from Finder) which reports:
Unable to resolve your shell environment: A system error occurred (spawn /opt/local/bin/bash ENOENT)
This is a totally reasonable complaint, since that binary no longer exists. It makes this complaint when launched from Finder, but not when launched from the terminal. There is no reference to this prior version of bash in my user settings.json file, nor is it in my .bashrc.
Where the heck could vscode be getting this path to bash from?!
Edit (2021-10-11): there is something strange going on here. If I open an integrated terminal in vscode:
$ echo $SHELL
/opt/local/bin/bash
$ ls -lh $SHELL
ls: /opt/local/bin/bash: No such file or directory
$ ps -p $$
PID TTY TIME CMD
45388 ttys001 0:00.12 /bin/bash -l
(there are no such problems in the regular macOS Terminal app)
Edit again (2021-10-12):
I tried resetting vscode (via rm -rf ~/Library/Application\ Support/Code).
I tried resetting vscode's cache (via rm -rf ~/Library/Caches/com.microsoft.*),
I downloaded iTerm2 and ran it; it loaded the correct shell (/opt/homebrew/bin/bash) without issue (tried this in hopes of determining if there was some other setting in macOS pointing at the old macports version of bash).
Had the same issue and was able to resolve this by changing the shell for the logged in user (using chsh -s, cf. the hint at the bottom of https://github.com/microsoft/vscode/issues/139867). As this change is not being picked up by VSCode in your currently logged in session, don't forget to explicitly log out and log back in again after performing this step.

nvm and gulp found on Visual Code terminal but not on linux terminal

I have Ubuntu LTS 20.04 running on wsl2 in Windows, this way I'm able to compile my JS/React code and run my php server in linux and use windows to code using Visual Studio Code.
This is running great, but a strange thing is happening, I installed nvm and gulp through the Visual Studio Code terminal and if I use them on the terminal it works fine but not if I do it outside the terminal (using Windows terminal), it says not found for both gulp and nvm.
I assume VSCode is adding a few things to the PATH but I don't know what to do for them to be found by the windows terminal (outisde VSCode terminal). Screen below. On the left is the result of running nvm list inside VS Code terminal and on the right on Ubuntu terminal, which can't find.
I'm a bit confused by your question. It sounds like you're installing programs on Windows through the VSCode terminal, and then trying to run them on Windows but it's not working. But then your screenshot shows the WSL Ubuntu prompt failing to find the command. Assuming you want to run these under WSL, log in to WSL Ubuntu and run this:
find / -name nvm
If you actually want to use the Windows terminal to run the program, you'll have to find where it is installed in Windows and make sure that's in your %PATH% but this doesn't seem like it's what you're trying to do.
The correct answer was provided by the comment from MindSwipe.
On VSCODE terminal if I "echo $PATH" it has the nvm directory in it while the $PATH on WSL doesn't, I assume VSCODE alters its own terminal PATH when the tools are installed using it instead of the global WSL path.
I've changed the WSL path and it's now working, how can I present the bounty to MindSwipe ?