Bug description
When I try to open a directory with code <directory>
, I get Error: Cannot find module '<directory>'
. This happens no matter what directory I try to open, whether it is in the WSL filesystem or the Windows filesystem.
To Reproduce
Steps to reproduce the behavior:
- Open a NixOS-WSL terminal (NOT the VSCode integrated terminal, since this uses a different binary for
code
)
- Navigate to any directory and type
code .
- Get error
Expected behavior
Should open the folder in VSCode Remote
Logs
My home-manager settings can be seen at https://github.com/kfish610/wsl-dots/blob/main/home.nix
neofetch
:
kfish@KDESKTOP
--------------
OS: NixOS 22.05 (Quokka) on Windows x86_64
Kernel: 5.10.102.1-microsoft-standard-WSL2
Uptime: 16 mins
Packages: 198 (nix-system), 4327 (nix-user), 71 (nix-default)
Shell: zsh 5.8.1
Terminal: Windows Terminal
CPU: AMD Ryzen 5 3600 (12) @ 3.600GHz
GPU: Microsoft Corporation Device 008e
Memory: 606MiB / 7910MiB
code $HOME
node:internal/modules/cjs/loader:990
throw err;
^
Error: Cannot find module '\\wsl.localhost\NixOS\home\kfish'
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: []
}
VSCODE_WSL_DEBUG_INFO=true code $HOME
(click expand):
Expand (this one's long)
+ COMMIT=c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
+ APP_NAME=code
+ QUALITY=stable
+ NAME=Code
+ SERVERDATAFOLDER=.vscode-server
++++ realpath '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code'
+++ dirname '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code'
++ dirname '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin'
+ VSCODE_PATH='/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code'
+ ELECTRON='/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe'
+ IN_WSL=false
+ '[' -n NixOS ']'
+ IN_WSL=true
+ '[' true = true ']'
+ export WSLENV=ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID
+ WSLENV=ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID
++ wslpath -m '/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js'
+ CLI='C:/Users/kfish/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/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe' 'C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/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/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe' 'C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js' --ms-enable-electron-run-as-node .
node:internal/modules/cjs/loader:990
throw err;
^
Error: Cannot find module '\\wsl.localhost\NixOS\home\kfish'
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: []
}
+ exit 1
For what it's worth, I also tested this in the default Ubuntu installation for WSL, and it worked. The debug output is:
VSCODE_WSL_DEBUG_INFO=true code $HOME
(click expand):
Expand (Ubuntu)
+ COMMIT=c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
+ APP_NAME=code
+ QUALITY=stable
+ NAME=Code
+ SERVERDATAFOLDER=.vscode-server
+ realpath /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code
+ dirname /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin/code
+ dirname /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/bin
+ VSCODE_PATH=/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code
+ ELECTRON=/mnt/c/Users/kfish/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:WT_SESSION::WT_PROFILE_ID
+ wslpath -m /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js
+ CLI=C:/Users/kfish/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/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/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=c:\Users\kfish\.vscode\extensions\ms-vscode-remote.remote-wsl-0.66.3
+ [ -n c:\Users\kfish\.vscode\extensions\ms-vscode-remote.remote-wsl-0.66.3 ]
+ wslpath -u c:\Users\kfish\.vscode\extensions\ms-vscode-remote.remote-wsl-0.66.3
+ WSL_CODE=/mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh
+ /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 stable /mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe code .vscode-server /home/kfish
+ [ -z .vscode-server ]
+ [ .vscode-server = .vscode-insiders ]
+ [ ! -t 0 ]
+ VSCODE_REMOTE_BIN=/home/kfish/.vscode-server/bin
+ AUTHORITY=wsl+default
+ [ Ubuntu ]
+ AUTHORITY=wsl+Ubuntu
+ dirname /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh
+ /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslDownload.sh c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 stable /home/kfish/.vscode-server/bin
+ [ ! -d /home/kfish/.vscode-server/bin/c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 ]
+ RC=0
+ [ 0 -ne 0 ]
+ mktemp /tmp/vscode-distro-env.XXXXXX
+ STORED_ENV=/tmp/vscode-distro-env.WD3oQH
+ env
+ dirname /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts/wslCode.sh
+ VSCODE_CLIENT_COMMAND=/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe VSCODE_CLIENT_COMMAND_CWD=/mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/scripts VSCODE_CLI_AUTHORITY=wsl+Ubuntu VSCODE_CLI_REMOTE_ENV=/tmp/vscode-distro-env.WD3oQH VSCODE_STDIN_FILE_PATH= WSLENV=VSCODE_CLI_REMOTE_ENV/w:ELECTRON_RUN_AS_NODE/w:WT_SESSION::WT_PROFILE_ID /home/kfish/.vscode-server/bin/c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5/bin/remote-cli/code /home/kfish
+ exit 0
As far as I can tell, the place it breaks is where it tries to locate the remote extension. If you isolate the line, you can run (the exact directory will vary slightly by your username):
> export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
> ELECTRON_RUN_AS_NODE=1 "/mnt/c/Users/kfish/AppData/Local/Programs/Microsoft VS Code/Code.exe" "C:/Users/kfish/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js" --ms-enable-electron-run-as-node --locate-extension ms-vscode-remote.remote-wsl
cli.js: bad option: --locate-extension
This is supposed to output the folder of the VSCode remote extension (and on Ubuntu the exact same command does output /mnt/c/Users/kfish/.vscode/extensions/ms-vscode-remote.remote-wsl-0.66.3/
for me), but instead it gives that weird error. I have absolutely no clue what makes NixOS-WSL different enough to cause that error, but it does only happen on NixOS.