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.localhostUbuntu-20.04mntcUsersJimDAppDataLocalProgramsMicrosoft VS CodeCode.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.localhostUbuntu-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?
3
Answers
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 flagPF
toF
, reboot wsl seems able to let you runcode
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
in my case I used the path "/etc/wsl-services-start.sh" This shell script contains only
Starting apache2 and mysql was the only thing I needed systemd for, so this works fine for me.