Skip to content

nodejs not working, exec format error #8151

Closed

Description

@wangqr

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

Activity

  1. elsaco commented on Mar 15, 2022

    @elsaco

    wangqr (@wangqr) what is the output of zsh --version?

    This is a screenshot of Arch running node in a zsh session:

    wsl_arch_node

  2. wangqr commented on Mar 15, 2022

    @wangqr
    Author

    It's zsh 5.8.1. Running under bash or strace gives save result though.

    wangqr@ocalhost:~$ zsh --version
    zsh 5.8.1 (x86_64-pc-linux-gnu)
    wangqr@ocalhost:~$ bash -c /usr/bin/node
    bash: line 1: /usr/bin/node: cannot execute binary file: Exec format error
    
  3. wangqr commented on Mar 15, 2022

    @wangqr
    Author

    Some more information:

    1. I do find a way to solve the issue:

      • In a docker, downgrade glibc from 2.35 to 2.33 using Archlinux Archive on 2022-02-14
      • Compile nodejs (asp checkout nodejs; cd nodejs/trunk; makepkg)
      • The resulting pkg.tar.zst will work fine on WSL1
      • Note: I built the package in a docker container running on a real archlinux machine. I haven't tried if downgrading glibc on WSL1 works. Because downgrading glibc is likely to break other packages, and fixing glibc issue in WSL1 is difficult.
    2. Compiling from source on WSL1 with the current glibc 2.35-2 will fail halfway with "Exec format error":

      g++ -o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/mkcodecache -pthread -rdynamic -m64 -Wl,-z,noexecstack -Wl,--whole-archive /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_snapshot.a -Wl,--no-whole-archive -Wl,-z,relro -Wl,-z,now -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Wl,--start-group /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/mkcodecache/src/node_snapshot_stub.o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/mkcodecache/src/node_code_cache_stub.o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/mkcodecache/tools/code_cache/mkcodecache.o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/mkcodecache/tools/code_cache/cache_builder.o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/libnode.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/deps/histogram/libhistogram.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/deps/uvwasi/libuvwasi.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_snapshot.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_libplatform.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/deps/llhttp/libllhttp.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_base_without_compiler.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_libbase.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_zlib.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_compiler.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_initializers.a -lz -luv -lbrotlidec -lbrotlienc -lcares -lnghttp2 -lcrypto -lssl -licui18n -licuuc -licudata -ldl -Wl,--end-group
      g++ -o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/node_mksnapshot -pthread -rdynamic -m64 -Wl,-z,noexecstack -Wl,--whole-archive /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_snapshot.a -Wl,--no-whole-archive -Wl,-z,relro -Wl,-z,now -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Wl,--start-group /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/node_mksnapshot/src/node_snapshot_stub.o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/node_mksnapshot/src/node_code_cache_stub.o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/node_mksnapshot/tools/snapshot/node_mksnapshot.o /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/libnode.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/deps/histogram/libhistogram.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/deps/uvwasi/libuvwasi.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_snapshot.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_libplatform.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/deps/llhttp/libllhttp.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_base_without_compiler.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_libbase.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_zlib.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_compiler.a /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj.target/tools/v8_gypfiles/libv8_initializers.a -lz -luv -lbrotlidec -lbrotlienc -lcares -lnghttp2 -lcrypto -lssl -licui18n -licuuc -licudata -ldl -Wl,--end-group
      LD_LIBRARY_PATH=/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/lib.host:/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../.; mkdir -p /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj/gen; "/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/mkcodecache" "/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj/gen/node_code_cache.cc"
      LD_LIBRARY_PATH=/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/lib.host:/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../.; mkdir -p /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj/gen; "/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/node_mksnapshot" "/home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj/gen/node_snapshot.cc"
    /bin/sh: line 1: /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/mkcodecache: cannot execute binary file: Exec format error
    make[1]: *** [node.target.mk:13: /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj/gen/node_code_cache.cc] Error 126
    make[1]: *** Waiting for unfinished jobs....
    /bin/sh: line 1: /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/node_mksnapshot: cannot execute binary file: Exec format error
    make[1]: *** [node.target.mk:26: /home/wangqr/nodejs/trunk/src/node-17.7.1/out/Release/obj/gen/node_snapshot.cc] Error 126
    rm 153bac10d83d38fd810d27369039858f690025da.intermediate 5fb9d05e8e7a809bf286a9a99430b12e50e12e34.intermediate 8c61239488171a14609c6ceaa1326c094866c228.intermediate 04b2e589442e78ea5b814ca0512cab45489617e8.intermediate
    make: *** [Makefile:113: node] Error 2
    ==> ERROR: A failure occurred in build().
        Aborting...
    
  4. gavenkoa commented on Mar 28, 2022

    @gavenkoa

    The same problem on Debian:

    bash# apt-cache show nodejs
    Package: nodejs
    Version: 16.13.2+really14.19.1~dfsg-6
    Installed-Size: 949
    Maintainer: Debian Javascript Maintainers <pkg-javascript-devel@alioth-lists.debian.net>
    Architecture: amd64
    Replaces: libnode72 (<< 12.22.10~dfsg~), libnode83 (<< 16.13.2+really14.19.1~dfsg~), nodejs-legacy
    Provides: node-types-node (= 14.18.12~16.13.2+really14.19.1~dfsg-6)
    Depends: libc6 (>= 2.2.5), libnode83 (= 16.13.2+really14.19.1~dfsg-6)
    

    When run:

    /usr/bin/node --version
    -bash: /usr/bin/node: cannot execute binary file: Exec format error
    

    libc6 is v2.33-7.

    bash# strace -f node --version
    execve("/usr/bin/node", ["node", "--version"], 0x7fffdc8ab7e0 /* 30 vars */) = -1 ENOEXEC (Exec format error)
    strace: exec: Exec format error
    +++ exited with 1 +++
    

    WSL 1:

    uname -a
    Linux msi 4.4.0-19041-Microsoft #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 GNU/Linux
    
  5. gavenkoa commented on Mar 28, 2022

    @gavenkoa

    As in #5875 following succeeds:

    /lib64/ld-linux-x86-64.so.2 /usr/bin/node --version
    v14.19.1
    
  6. gavenkoa commented on Mar 28, 2022

    @gavenkoa

    Similar symptoms in #5154

  7. qyb commented on Apr 22, 2022

    @qyb

    the same error: #8219

  8. srogerf commented on May 30, 2022

    @srogerf

    Had the same issues and upgrading to WSL 2 worked for me
    wsl --set-version <name> 2

    Use from
    wsl -l -v

    I 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

  9. gavenkoa commented on Aug 3, 2022

    @gavenkoa

    Any progress? I upgraded to 21H2:

    cmd /c ver
    Microsoft Windows [Version 10.0.19044.1826]
    

    but still happens:

    # strace -f node --help
    execve("/usr/bin/node", ["node", "--help"], 0x7ffff7a99db0 /* 31 vars */) = -1 ENOEXEC (Exec format error)
    strace: exec: Exec format error
    +++ exited with 1 +++
    
  10. gavenkoa commented on Aug 3, 2022

    @gavenkoa

    As a workaround I updated npm tool (actual file is /usr/share/nodejs/npm/bin/npm-cli.js):

    #!/lib64/ld-linux-x86-64.so.2 /usr/bin/node
    //#!/usr/bin/env node
    require('../lib/cli.js')(process)
  11. gavenkoa commented on Aug 3, 2022

    @gavenkoa

    It is possible to make a workaround for node itself:

    sudo mv /usr/bin/node /usr/bin/node-orig
    printf '#!/bin/sh\nexec /lib64/ld-linux-x86-64.so.2 /usr/bin/node-orig "$@"' | sudo tee /usr/bin/node
    sudo chmod a+x /usr/bin/node

    My previous fix for npm won't work with the updated node executable, needs to be reverted.

  12. andreineculau commented on Aug 3, 2022

    @andreineculau

    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

  13. gavenkoa commented on Aug 3, 2022

    @gavenkoa

    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.so loads image like the exec call but avoids problems in Microsoft's lxcore.sys. It is better for sysadmins who are afraid binary patching with elftools.elf.elffile import ELFFile ))

  14. wangqr commented on Aug 4, 2022

    @wangqr
    Author
    sudo mv /usr/bin/node /usr/bin/node-orig
    printf '#!/bin/sh\nexec /lib64/ld-linux-x86-64.so.2 /usr/bin/node-orig "$@"' | sudo tee /usr/bin/node
    sudo chmod a+x /usr/bin/node

    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-sass will fail:

    wangqr@ocalhost:~$ npm i node-sass
    npm WARN deprecated har-validator@5.1.5: this library is no longer supported
    npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
    npm ERR! code 1
    npm ERR! path /home/wangqr/node_modules/node-sass
    npm ERR! command failed
    npm ERR! command sh /tmp/postinstall-35c885a8.sh
    npm ERR! Building: /usr/lib/ld-linux-x86-64.so.2 /home/wangqr/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
    npm ERR! /home/wangqr/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js: error while loading shared libraries: /home/wangqr/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js: invalid ELF header
    npm ERR! node-gyp not found!
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/wangqr/.npm/_logs/2022-08-04T10_51_18_640Z-debug-0.log
    
  15. gavenkoa commented on Aug 4, 2022

    @gavenkoa

    wangqr (@wangqr) wrote:

    For example, npm i node-sass will fail:

    I had the same issue. I think you altered npm script, I warned about this above;

    My previous fix for npm won't work with the updated node executable, needs to be reverted.

    If node executable is operable every tool is Nodejs toolchain will wok.

  16. 13 remaining items

  17. hiteshsahu commented on Aug 8, 2024

    @hiteshsahu

    Complete answer

    
    // start wsl terminal
    wsl    
    // Install node 16 
    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    // Update Node Js 
    sudo npm install -g n
    sudo n stable
    
  18. splitice commented on Oct 9, 2024

    @splitice

    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.

  19. splitice commented on Oct 9, 2024

    @splitice

    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

  20. benhillis commented on Dec 9, 2024

    @benhillis
    Member

    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.

  21. gustavosbarreto commented on Dec 9, 2024

    @gustavosbarreto

    Ben Hillis (@benhillis) This issue is easily reproducible. I'm not sure if you've tried it.

    Image

  22. vadimkantorov commented on Dec 10, 2024

    @vadimkantorov

    Ben Hillis (@benhillis) Yep, it well reproduces for me on Microsoft Windows [Version 10.0.22631.4460] (output of ver - newer than 22621)

    WSLv1 with Ubuntu 24.04:

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 24.04 LTS
    Release:        24.04
    Codename:       noble
    
    $ sudo apt install nodejs
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    The following additional packages will be installed:
      libcares2 libnode109 libuv1t64 node-acorn node-busboy node-cjs-module-lexer node-undici node-xtend nodejs-doc
    Suggested packages:
      npm
    The following NEW packages will be installed:
      libcares2 libnode109 libuv1t64 node-acorn node-busboy node-cjs-module-lexer node-undici node-xtend nodejs nodejs-doc
    0 upgraded, 10 newly installed, 0 to remove and 195 not upgraded.
    Need to get 16.2 MB of archives.
    After this operation, 70.7 MB of additional disk space will be used.
    Do you want to continue? [Y/n] Y
    ...
    
    $ node
    -bash: /usr/bin/node: cannot execute binary file: Exec format error
    
    $ nodejs
    -bash: /usr/bin/nodejs: cannot execute binary file: Exec format error
    
    $ npm
    /usr/bin/node: 1: Syntax error: "(" unexpected
    
  23. vadimkantorov commented on Feb 15, 2025

    @vadimkantorov

    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 --version

    Works:

    curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
    sudo apt-get install -y nodejs
    node --version
  24. splitice commented on Feb 18, 2025

    @splitice

    Yes, this is not fixed.

  25. gaoqiangks commented on Sep 23, 2025

    @gaoqiangks

    It's still there.

  26. MakaEdgarTFS commented on Nov 19, 2025

    @MakaEdgarTFS

    Still present.

  27. suewonjp commented on Jan 13, 2026

    @suewonjp

    Still present.

  28. lygstate commented on Jun 1, 2026

    @lygstate

    Still present on

    Microsoft Windows [Version 10.0.26100.32860]
    (c) Microsoft Corporation. All rights reserved.
    

    Better reopen this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions