WSL: nodejs not working, exec format error
Version
Microsoft Windows [Version 10.0.19044.1586]
WSL Version
- WSL 2
- WSL 1
Kernel Version
4.4.0-19041-Microsoft
Distro Version
Arch
Other Software
No response
Repro Steps
Install nodejs from Archlinux repo with pacman -S nodejs, and run node
Expected Behavior
nodejs starts
Actual Behavior
nodejs does not start. exec format error.
wangqr@ocalhost:~$ node
zsh: exec format error: node
Diagnostic Logs
nodejs can start if we manually invoke ld-linux, although it is already the interpreter in the ELF.
wangqr@ocalhost:~$ /usr/bin/node
zsh: exec format error: /usr/bin/node
wangqr@ocalhost:~$ strace /usr/bin/node
execve("/usr/bin/node", ["/usr/bin/node"], 0x7ffff42aefa0 /* 25 vars */) = -1 ENOEXEC (Exec format error)
strace: exec: Exec format error
+++ exited with 1 +++
wangqr@ocalhost:~$ /lib/ld-linux-x86-64.so.2 /usr/bin/node
Welcome to Node.js v17.7.1.
Type ".help" for more information.
>
wangqr@ocalhost:~$ /lib64/ld-linux-x86-64.so.2 /usr/bin/node
Welcome to Node.js v17.7.1.
Type ".help" for more information.
>
wangqr@ocalhost:~$ file /usr/bin/node
/usr/bin/node: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=10ec67f51a763d04ac6e1fe305ce214fb40eabda, for GNU/Linux 4.4.0, stripped
wangqr@ocalhost:~$ readelf -h /usr/bin/node
ELF Header:
Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - GNU
ABI Version: 0
Type: DYN (Position-Independent Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x6aa570
Start of program headers: 64 (bytes into file)
Start of section headers: 34087608 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 16
Size of section headers: 64 (bytes)
Number of section headers: 30
Section header string table index: 29
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 16
- Comments: 37 (1 by maintainers)
Links to this issue
Commits related to this issue
- Use prettier from upstream in WSL Otherwise I get the error message as described here: https://github.com/microsoft/WSL/issues/8151 — committed to Nebucatnetzer/nixos by deleted user 4 years ago
Had the same issues and upgrading to WSL 2 worked for me
wsl --set-version <name> 2Use <name> from
wsl -l -vI did follow https://docs.microsoft.com/en-us/windows/wsl/install-manual#step-3---enable-virtual-machine-feature (and step 4) but node is working for me now. This is with Ubuntu 22.04
Update to WSL v2 as @srogerf suggested - worked for me. Ubuntu 22.04.1 Node v12.22.9
I got the same problem. Win10 21H2 and Ubuntu 22.04 WSL1
after
sudo apt install nodejsonly get/usr/bin/node: cannot execute binary file: Exec format errorI fixed this problem by using nodejs package https://github.com/nodesource/distributions/blob/master/README.md#debinstall
It is possible to make a workaround for
nodeitself:My previous fix for
npmwon’t work with the updatednodeexecutable, needs to be reverted.@qchencc 's solution worked for me on WSL1 + Ubuntu 18.04 + Windows 11 22H2, but required switching to Node v16:
The suggestion “upgrade to WSL2” is both partly off topic and also potentially wrong. It’s potentially very wrong under certain contexts because WSL2 requires the Windows operating system to turn on the Hypervisor. This is completely unnecessary when there is no other requirement for it because the Hypervisor takes up resources to run everything from boot time (including the Operating System of Windows itself (because it’s a type 1 Hypervisor instead of a type 2)).
As in https://github.com/microsoft/WSL/issues/5875 following succeeds:
This bash script fixed it for me. I ran sudo ./wsl-fix-exec-format-error.sh /usr/bin/node wsl-fix-exec-format-error.sh.txt
I also encountered the same problem and solved it by:
Somehow the 23 version of node fails with the same error while 22 version does not:
All on WSLv1 Ubuntu 24.04:
Breaks with exec format error:
Works:
I’ve been trying to get a repro of this invalid elf format error but haven’t found one that works on new versions of Windows. If you can reproduce this on windows 22621 or later please let me know by opening a new issue.
Similar issue with WSL1 + Ubuntu 22.04:
Because npm cannot start, I can’t even
npm install semverattaching
/usr/bin/nodein bug.zipThis is kind of surprising that such fundamental set-up is currently broken on WSLv1 😃
@benhillis This issue is easily reproducible. I’m not sure if you’ve tried it.
@andreineculau I understand the solution, the initial analysis was done by https://github.com/microsoft/WSL/issues/8219#issuecomment-1094123281 stating that it is a bug in
lxcore.sys.ls.soloads image like theexeccall but avoids problems in Microsoft’slxcore.sys. It is better for sysadmins who are afraid binary patching withelftools.elf.elffile import ELFFile))@gavenkoa my general fix is to run
wsl-fix-exec-format-error $(realpath $(command -v node))The script is here: https://github.com/ysoftwareab/yplatform/blob/master/bin/wsl-fix-exec-format-error
Based on https://gist.github.com/the-moog/179753aacc52b262d1068878d520e9c9 by @the-moog @wangqr 🙌
Running realpath is needed because sometimes (eg homebrew) node in your $PATH is a symlink
PS: I have found that I need to patch gzip as well, not just node, so a generic patch script is really good to have
As a workaround I updated
npmtool (actual file is/usr/share/nodejs/npm/bin/npm-cli.js):the same error: https://github.com/microsoft/WSL/issues/8219
The same problem on Debian:
When run:
libc6 is v2.33-7.
WSL 1:
It’s zsh 5.8.1. Running under bash or strace gives save result though.