Repository navigation
nodejs not working, exec format error #8151
Copy link
Copy link
Closed
Labels
Description
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
Reactions are currently unavailable
Activity
elsaco commentedon Mar 15, 2022
wangqr (@wangqr) what is the output of
zsh --version?This is a screenshot of
Archrunningnodein azshsession:wangqr commentedon Mar 15, 2022
It's zsh 5.8.1. Running under bash or strace gives save result though.
wangqr commentedon Mar 15, 2022
Some more information:
I do find a way to solve the issue:
asp checkout nodejs; cd nodejs/trunk; makepkg)Compiling from source on WSL1 with the current glibc 2.35-2 will fail halfway with "Exec format error":
gavenkoa commentedon Mar 28, 2022
The same problem on Debian:
When run:
libc6 is v2.33-7.
WSL 1:
gavenkoa commentedon Mar 28, 2022
As in #5875 following succeeds:
gavenkoa commentedon Mar 28, 2022
Similar symptoms in #5154
qyb commentedon Apr 22, 2022
the same error: #8219
srogerf commentedon May 30, 2022
Had the same issues and upgrading to WSL 2 worked for me
wsl --set-version <name> 2Use 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
gavenkoa commentedon Aug 3, 2022
Any progress? I upgraded to 21H2:
but still happens:
gavenkoa commentedon Aug 3, 2022
As a workaround I updated
npmtool (actual file is/usr/share/nodejs/npm/bin/npm-cli.js):gavenkoa commentedon Aug 3, 2022
It is possible to make a workaround for
nodeitself:My previous fix for
npmwon't work with the updatednodeexecutable, needs to be reverted.andreineculau commentedon Aug 3, 2022
Oleksandr Gavenko (@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 Jay (@the-moog) wangqr (@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
gavenkoa commentedon Aug 3, 2022
Andrei Neculau (@andreineculau) I understand the solution, the initial analysis was done by #8219 (comment) 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))wangqr commentedon Aug 4, 2022
Oleksandr Gavenko (@gavenkoa) This method can be problematic for modules that assume argv[0] be node itself when running node. For example,
npm i node-sasswill fail:gavenkoa commentedon Aug 4, 2022
wangqr (@wangqr) wrote:
I had the same issue. I think you altered
npmscript, I warned about this above;If
nodeexecutable is operable every tool is Nodejs toolchain will wok.13 remaining items
hiteshsahu commentedon Aug 8, 2024
Complete answer
splitice commentedon Oct 9, 2024
This issue is very annoying and still existing in WSL1.
The wsl-fix-exec-format-error.sh.txt script does work but is quite tedious when trying to for example fix all the binaries used in a nodejs make execution.
splitice commentedon Oct 9, 2024
Heres a patch for node that disables the larger code page sizes that does not work on WSL1 during the build process. It also detects WSL1. It doesnt currently work on the main node binary however, there appears to be somewhere else forcing it to 8kb instead of the default 4kb that WSL1 incorrectly assumes so you will need to call the python script on the resulting binary for now.
https://github.com/HalleyAssist/node/commit/1c48afc4e51f6306b1eedb0289b7e2397bf7fdbc.patch
benhillis commentedon Dec 9, 2024
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.
gustavosbarreto commentedon Dec 9, 2024
Ben Hillis (@benhillis) This issue is easily reproducible. I'm not sure if you've tried it.
vadimkantorov commentedon Dec 10, 2024
Ben Hillis (@benhillis) Yep, it well reproduces for me on
Microsoft Windows [Version 10.0.22631.4460](output ofver- newer than 22621)WSLv1 with Ubuntu 24.04:
vadimkantorov commentedon Feb 15, 2025
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:
curl -fsSL https://deb.nodesource.com/setup_23.x | sudo -E bash - sudo apt-get install -y nodejs node --versionWorks:
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt-get install -y nodejs node --versionsplitice commentedon Feb 18, 2025
Yes, this is not fixed.
gaoqiangks commentedon Sep 23, 2025
It's still there.
MakaEdgarTFS commentedon Nov 19, 2025
Still present.
suewonjp commentedon Jan 13, 2026
Still present.
lygstate commentedon Jun 1, 2026
Still present on
Better reopen this issue
Docs: WSL1 vs WSL2 node install failure, plus e2e note