WSL icon indicating copy to clipboard operation
WSL copied to clipboard

nodejs not working, exec format error

Open kotenok2000 opened this issue 1 year ago • 14 comments

Windows Version

Microsoft Windows [Version 10.0.26100.2454]

WSL Version

2.3.26.0

Are you using WSL 1 or WSL 2?

  • [ ] WSL 2
  • [x] WSL 1

Kernel Version

4.4.0-26100-Microsoft

Distro Version

Ubuntu 22.04

Other Software

nvm 0.39.7 node 23.3.0

Repro Steps

  1. Install nvm from https://github.com/nvm-sh/nvm
  2. Run nvm install v23.3.0
  3. run node.

Expected Behavior

Node runs without errors.

Actual Behavior

Image

Diagnostic Logs

WslLogs-2024-12-10_01-37-00.zip

kotenok2000 avatar Dec 09 '24 22:12 kotenok2000

https://github.com/microsoft/WSL/issues/8151#issuecomment-2529656728

kotenok2000 avatar Dec 09 '24 22:12 kotenok2000

The log file doesn't contain any WSL traces. Please make sure that you reproduced the issue while the log collection was running.

Diagnostic information
Detected appx version: 2.3.26.0
Found no WSL traces in the logs

github-actions[bot] avatar Dec 09 '24 22:12 github-actions[bot]

Diagnostic information
Detected appx version: 2.3.26.0
Detected user visible error: Wsl/Service/CreateInstance/0xd00002fe

github-actions[bot] avatar Dec 09 '24 22:12 github-actions[bot]

OK. Looks like our elf parser doesn't like that one of the elf program headers has an alignment that doesn't match the other program header alignments. We're probably being too strict here...

benhillis avatar Dec 10 '24 18:12 benhillis

Still unfixed on WSL version: 2.4.10.0 pre-release

kotenok2000 avatar Feb 11 '25 14:02 kotenok2000

would be nice to be fixed this for WSL1, there are cases where people would like to use WSL1 instead of WSL2

alessiot89 avatar Mar 26 '25 12:03 alessiot89

Indeed this would be great to get fixed! WSL1 still has many advantages for me in most situations.

CherryDT avatar Sep 21 '25 16:09 CherryDT

Just want to chime in that yes, this is still impacting WSL 1 users. I just got bitten by this when cursor CLI auto-updated itself and pulled in a binary with this problem.

https://forum.cursor.com/t/newest-cursor-cli-has-broken-node-binary-on-wsl-exec-format-error/135913/4

zachmu avatar Oct 06 '25 21:10 zachmu

I have found a way to artificially produce misaligned elfs by using llvm bolt post-link optimizer.

kotenok2000 avatar Oct 21 '25 23:10 kotenok2000

@benhillis Any news?

kotenok2000 avatar Oct 22 '25 01:10 kotenok2000

The same here. For some reason, I have to use WSL1. Node.js v24 has become active LTS, but I'm forced to stay on v22.

doff6 avatar Nov 04 '25 07:11 doff6

I have been using this script to patch node executable.

wsl-fix-exec-format-error.sh.txt

kotenok2000 avatar Nov 04 '25 07:11 kotenok2000

I have been using this script to patch node executable.

wsl-fix-exec-format-error.sh.txt

Thanks for this script, it works.But make sure pyelftools should be installed before.

ivan@wangyifan101:~> sudo xbps-install python3-pyelftools

Name               Action    Version           New version            Download size
python3-pyelftools install   -                 0.32_2                 152KB

Size to download:              152KB
Size required on disk:         714KB
Space available on disk:        61GB

Do you want to continue? [Y/n]

[*] Downloading packages
python3-pyelftools-0.32_2.x86_64.xbps.sig2: 512B [avg rate: 4505KB/s]
python3-pyelftools-0.32_2.x86_64.xbps: 152KB [avg rate: 1768KB/s]
python3-pyelftools-0.32_2: verifying RSA signature...

[*] Collecting package files
python3-pyelftools-0.32_2: collecting files...

[*] Unpacking packages
python3-pyelftools-0.32_2: unpacking ...
python3-pyelftools-0.32_2: registered 'pyelftools' alternatives group
Creating 'pyelftools' alternatives group symlink: readelf.py -> /usr/bin/readelf.py3

[*] Configuring unpacked packages
python3-pyelftools-0.32_2: configuring ...
Byte-compiling python3.13 code for module elftools...
Updating ldconfig(8) cache...
python3-pyelftools-0.32_2: installed successfully.

1 downloaded, 1 installed, 0 updated, 1 configured, 0 removed, 0 on hold.
ivan@wangyifan101:~> sudo python3 wsl-fix-exec-format-error.sh.txt /usr/sbin/node
Backing up /usr/sbin/node to /usr/sbin/node.bak
Fixing /usr/sbin/node....
Changing alignment of program header 3 from 8192 to 4096
Changing alignment of program header 4 from 2097152 to 4096
Success

ivan@wangyifan101:~> node
Welcome to Node.js v22.15.0.
Type ".help" for more information.
>
ivan@wangyifan101:~> 

wyf9661 avatar Nov 26 '25 03:11 wyf9661