Skip to content
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

WSL with systemd: Cannot open VSCode from WSL terminal #179252

Closed
RobbertProost opened this issue Apr 5, 2023 · 11 comments
Closed

WSL with systemd: Cannot open VSCode from WSL terminal #179252

RobbertProost opened this issue Apr 5, 2023 · 11 comments
Assignees

Comments

@RobbertProost
Copy link

RobbertProost commented Apr 5, 2023

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.77.0
  • OS Version: Windows 11 22H2
  • WSL Version: 1.1.6.0
  • WSL distribution: Ubuntu 22.04

Steps to Reproduce:

  1. Enable systemd in WSL
  2. Restart WSL
  3. Open a WSL terminal
  4. Excecute code .

Expected behavior:

VSCode opens with the current directory

Actual behavior:

VSCode doesn't open and shows the following output:

node:internal/modules/cjs/loader:990
  throw err;
  ^

Error: Cannot find module '\\wsl.localhost\Ubuntu\home\<user>'
    at Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
    at Module._load (node:internal/modules/cjs/loader:832:27)
    at c._load (node:electron/js2c/asar_bundle:5:13343)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

When trying to launch VSCode without any arguments, it doesn't output anything in the terminal, but it also doesn't start VSCode.

With systemd disabled in WSL, everything works as expected. So it must have something todo with the way the WSL environment is started.
Not sure if this is an issue with VSCode or WSL.

@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.77.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@RobbertProost
Copy link
Author

Re-tested with v1.77.0: same behavior

@aeschli
Copy link
Contributor

aeschli commented Apr 6, 2023

Can you run VSCODE_WSL_DEBUG_INFO=true code-insiders . and paste the output here?

@RobbertProost
Copy link
Author

robbert@LAPTOP-ROBBERTP ~ % VSCODE_WSL_DEBUG_INFO=true code-insiders .
+ COMMIT=8f74fbfd1f2d8f6268a42df131726b218aafe511
+ APP_NAME=code-insiders
+ QUALITY=insider
+ NAME=Code - Insiders
+ SERVERDATAFOLDER=.vscode-server-insiders
+ realpath /mnt/c/Program Files/Microsoft VS Code Insiders/bin/code-insiders
+ dirname /mnt/c/Program Files/Microsoft VS Code Insiders/bin/code-insiders
+ dirname /mnt/c/Program Files/Microsoft VS Code Insiders/bin
+ VSCODE_PATH=/mnt/c/Program Files/Microsoft VS Code Insiders
+ ELECTRON=/mnt/c/Program Files/Microsoft VS Code Insiders/Code - Insiders.exe
+ IN_WSL=false
+ [ -n Ubuntu ]
+ IN_WSL=true
+ [ true = true ]
+ export WSLENV=ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID
+ wslpath -m /mnt/c/Program Files/Microsoft VS Code Insiders/resources/app/out/cli.js
+ CLI=C:/Program Files/Microsoft VS Code Insiders/resources/app/out/cli.js
+ WSL_EXT_ID=ms-vscode-remote.remote-wsl
+ ELECTRON_RUN_AS_NODE=1 /mnt/c/Program Files/Microsoft VS Code Insiders/Code - Insiders.exe C:/Program Files/Microsoft VS Code Insiders/resources/app/out/cli.js --ms-enable-electron-run-as-node --locate-extension ms-vscode-remote.remote-wsl
+ cat /tmp/remote-wsl-loc.txt
+ WSL_EXT_WLOC=
+ [ -n  ]
+ ELECTRON_RUN_AS_NODE=1 /mnt/c/Program Files/Microsoft VS Code Insiders/Code - Insiders.exe C:/Program Files/Microsoft VS Code Insiders/resources/app/out/cli.js --ms-enable-electron-run-as-node .
node:internal/modules/cjs/loader:1013
  throw err;
  ^

Error: Cannot find module '\\wsl.localhost\Ubuntu\home\robbert'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1010:15)
    at Module._load (node:internal/modules/cjs/loader:858:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    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: []
}
+ exit 1

@aeschli
Copy link
Contributor

aeschli commented Apr 6, 2023

I assume you are a user of the WSL extension, correct?

The script could not find the location of the WSL extension. So it tried to open the mounted folder locally from the windows side, which ran into some strange error.

  • Can you check that the WSL extension is installed?
    • If you run code-insiders --locate-extension ms-vscode-remote.remote-wsl in a windows command prompt, does that give you back something?
    • If that returns a location, in the WSL terminal, run ELECTRON_RUN_AS_NODE=1 '/mnt/c/Program Files/Microsoft VS Code Insiders/Code - Insiders.exe' 'C:/Program Files/Microsoft VS Code Insiders/resources/app/out/cli.js' --ms-enable-electron-run-as-node --locate-extension ms-vscode-remote.remote-wsl and see if that works as well.

@RobbertProost
Copy link
Author

Yes I am. And when using WSL without systemd enabled, everything is working as expected. So it seems the extension is installed correctly.

Running the suggested command in a Windows command prompt shows:
c:\Users\<user>\.vscode-insiders\extensions\ms-vscode-remote.remote-wsl-0.78.0

When running the second suggested command in a WSL terminal, it actually opens VSCode but according to the WSL extension not as a WSL window. The WSL extension shows the following pop-up:
image

By clicking on Reopen Folder in WSL it restarts VSCode and it works as expected. Although the terminal remains in 'active' while the VSCode is open and only returns when VSCode is closed.

@aeschli
Copy link
Contributor

aeschli commented Apr 6, 2023

Ah sorry, the command to run in the WSL terminal is:
WSLENV=ELECTRON_RUN_AS_NODE/w ELECTRON_RUN_AS_NODE=1 '/mnt/c/Program Files/Microsoft VS Code Insiders/Code - Insiders.exe' 'C:/Program Files/Microsoft VS Code Insiders/resources/app/out/cli.js' --ms-enable-electron-run-as-node --locate-extension ms-vscode-remote.remote-wsl

@RobbertProost
Copy link
Author

It outputs: C:/Program Files/Microsoft VS Code Insiders/resources/app/out/cli.js: bad option: --locate-extension

@aeschli
Copy link
Contributor

aeschli commented Apr 6, 2023

bad option is not something we output in VS Code, and I suspect it's related to the WSL interop.
We want to file this against https://github.com/microsoft/wsl

I'll do some more testing on a different machine to see if I can reproduce.

@RobbertProost
Copy link
Author

It seems to be related to this issue: microsoft/WSL#8843
When I apply the suggested change in /usr/lib/binfmt.d/WSLInterop.conf it works as expected.

@aeschli
Copy link
Contributor

aeschli commented Apr 11, 2023

Thanks for finding the related issue!

Closing the issue here.

@aeschli aeschli closed this as completed Apr 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants