-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Trying to run "code <directory>" in terminal gives "Error: Cannot find module '<directory>'" #97
Comments
I should note, I do have VSCode remote working in general, I just have to open VSCode normally first and then click New WSL Window. It's just very annoying to have to do that in order to open a folder, rather than just being able to do it from the terminal. |
This seems to be (yet another) interop issue. Can you try setting |
@nzbr Oh that did fix it, is there anything im missing out on by having that off? Thanks though! |
It is needed to be able to register binfmt handlers without breaking running .exe files from NixOS. If you don't use that, you don't need |
Wild guess: when have you last updated the nixos-wsl channel/input? This might be fixed by 28185e3 |
I definitely have the latest commit, and as soon as I set |
Please try #99 |
Getting the exact same error on Windows 10. I'm on the latest NixOS-WSL commit. Setting Output from
|
Can you run |
Tested with c/windows/System32
❯ nix run nixpkgs#file /run/binfmt/WSLinterop
/run/binfmt/WSLinterop: cannot open `/run/binfmt/WSLinterop' (No such file or directory) (also, I installed this system fresh an hour ago from the nixos-wsl-installer-fixed.tar.gz file from releases) |
Can you try installing from the latest tarball? |
Thanks for the idea -- makes a ton of sense, should have thought of that. Unfortunately, it didn't work. Installed from the link provided and got the following: [nixos@nixos:~]$ mkdir test
[nixos@nixos:~]$ touch test/index.js
[nixos@nixos:~]$ cd test
[nixos@nixos:~/test]$ code .
node:internal/modules/cjs/loader:990
throw err;
^
Error: Cannot find module '\\wsl$\nixtest\mnt\c\Program Files\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: []
} For [nixos@nixos:~/test]$ nix run nixpkgs#file /run/binfmt/WSLInterop
/run/binfmt/WSLInterop: symbolic link to /nix/store/8rw41lzvsyzvrcfa33b05i1h4mh97jk3-nixos-wsl-binfmt-hack |
Does setting |
Looks like Installing The details of my testing are below. Steps taken
ResultsWith PS C:\Users\Alexja> wsl -d nixtest
Copying /usr/share/applications
Copying /usr/share/icons
setting up /etc...
Starting systemd...
[nixos@US-ALEXJA-L:/mnt/c/Users/Alexja]$ code .
node:internal/modules/cjs/loader:990
throw err;
^
Error: Cannot find module 'C:\mnt\c\Program Files\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: []
} With PS C:\Users\Alexja> wsl -d nixtest
Copying /usr/share/applications
Copying /usr/share/icons
setting up /etc...
Starting systemd...
[nixos@US-ALEXJA-L:/mnt/c/Users/Alexja]$ code .
ERROR: Failed to download the VS Code server. 'wget' not installed.
Please install wget:
Debian/Ubuntu: sudo apt-get install wget And after getting a nix-shell with [nix-shell:/mnt/c/Users/Alexja]$ which wget
/nix/store/a1csfsg5xb0dqdikxdjx8r2h055gw7fw-wget-1.21.3/bin/wget
[nix-shell:/mnt/c/Users/Alexja]$ code .
Updating VS Code Server to version 4af164ea3a06f701fe3e89a2bcbb421d2026b68f
Removing previous installation...
Installing VS Code Server for x64 (4af164ea3a06f701fe3e89a2bcbb421d2026b68f)
Downloading: 100%
Unpacking: 100%
Unpacked 2377 files and folders to /home/nixos/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f.
/home/nixos/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f/bin/remote-cli/code: line 12: /home/nixos/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f/node: No such file or directory This is the other VSCode-specific error I've been seeing. To get around it, I do the following [nix-shell:/mnt/c/Users/Alexja]$ cd /home/nixos/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f/
[nix-shell:~/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f]$ nix build nixpkgs#nodejs
[nix-shell:~/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f]$ rm node
[nix-shell:~/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f]$ ln -s result/bin/node node
[nix-shell:~/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f]$ ls -la
total 84
drwxr-xr-x 6 nixos users 4096 Jun 14 10:17 .
drwxr-xr-x 3 nixos users 4096 Jun 14 10:12 ..
drwxr-xr-x 4 nixos users 4096 Jun 8 11:50 bin
drwxr-xr-x 33 nixos users 4096 Jun 8 11:50 extensions
-rw-r--r-- 1 nixos users 13380 Jun 8 11:49 LICENSE
lrwxrwxrwx 1 nixos users 15 Jun 14 10:17 node -> result/bin/node
drwxr-xr-x 166 nixos users 4096 Jun 8 11:50 node_modules
drwxr-xr-x 3 nixos users 4096 Jun 8 11:50 out
-rw-r--r-- 1 nixos users 62 Jun 8 11:49 package.json
-rw-r--r-- 1 nixos users 36857 Jun 8 11:50 product.json
lrwxrwxrwx 1 nixos users 58 Jun 14 10:17 result -> /nix/store/5yd3np2ljp6xpj1nsf1p3kdi3qaq8h4b-nodejs-16.15.0
-rwxr-xr-x 1 nixos users 240 Jun 8 11:47 server.sh
[nix-shell:~/.vscode-server/bin/4af164ea3a06f701fe3e89a2bcbb421d2026b68f]$ code .
< VSCode opens successfully > |
I solved that with the following bash function which works with user and system wide code installations and without having windows binaries in code() {
if [[ -n ${WSL_DISTRO_NAME:-} ]]; then
local bin node node_package user_install system_install
if [[ -d ~/.vscode-server/bin ]]; then
for bin in ~/.vscode-server/bin/*/node; do
if [[ ! -L $bin || -n $(find "$bin" -mtime +10 -print) ]]; then
echo "
Fixing vendored nodejs...
If a new VSCode is downloaded please re-run to fix a new download
"
node_package=nixpkgs#nodejs-16_x
[[ ! -v node ]] && node=$(nix eval "$node_package")/bin/node
[[ ! -f $node ]] && nix build "/nix/var/nix/gcroots/per-user/$USER/$node_package"
ln -s -fs "$node" "$bin"
ln -s -fs "$bin" "$(uuidgen)"
fi
done
else
echo "
VSCode is now downloading its binary blob remote server.
After that please re-run to fix the vendored node binary.
"
fi
user_install="/mnt/c/Users/$(wslvar USERNAME)/AppData/Local/Programs/Microsoft VS Code/bin/code"
system_install="/mnt/c/Program Files/Microsoft VS Code/bin/code"
if [[ -e $user_install ]]; then
"$user_install" "$@"
else
if [[ -e $system_install ]]; then
"$system_install" "$@"
else
ansi --red "No VSCode installation found"
fi
fi
else
command code "$@"
fi
} |
@SuperSandro2000 i am trying this again and wanted to try your approach, but something seems to be going wrong?
|
You're WSL probably run out of memory while trying to eval/build nodejs |
huh you're probably right, but I can not really see that? checking taskmanager I never go over 60% and checking free there still seems to be over 6GB free and swap not being used at all? am I overlooking a metric? |
The little function is not written very robust and well could be broken outside of my machines but try running the following and see what happens: nix eval nixpkgs#nodejs-16_x and then symlink that to where vscode-server downloaded its node binary and add a gcroot for it. |
sorry for the late reply, hmm yea also just fails with a stackoverflow :/ |
Is this still an issue? |
Let's keep all the VSCode issues to #238. |
Bug description
When I try to open a directory with
code <directory>
, I getError: 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:
code
)code .
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
:code $HOME
VSCODE_WSL_DEBUG_INFO=true code $HOME
(click expand):Expand (this one's long)
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)
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):
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.The text was updated successfully, but these errors were encountered: