node fails in WSL with exec format error
zsh: exec format error: nodeShort answer
The node that zsh finds is probably a Windows program on the PATH, and is not a Linux program. Check which node runs, install Node.js inside WSL, and keep Windows path entries from shadowing it. Also check that interop has not been turned off, which blocks Windows processes from launching.
Fix it fast
1Find out which cause you have
See which node zsh resolves. A path under /mnt/c means it is the Windows one.
which -a node2Match what you see, then jump to its fix
What does the error look like?
zsh: exec format error: node
Cause 1 of 2
Windows interop is switched off
1Check
WSL runs Windows tools as native commands. Interop can be disabled in /etc/wsl.conf, or for one session via binfmt_misc.
cat /etc/wsl.conf
cat /proc/sys/fs/binfmt_misc/WSLInterop2Fix
Under [interop], enabled=false blocks Windows processes. Set it to true, or better, install Node.js inside WSL.
[interop]
enabled=true3Verify
Restart WSL, then run a Windows tool and node.
# in PowerShell
wsl --shutdownConfirmed by learn.microsoft.com
Cause 2 of 2
A Windows PATH entry shadows a Linux Node.js
1Check
appendWindowsPath defaults to true, so Windows path elements are added to the Linux PATH.
echo $PATH | tr ':' '\n' | grep mnt2Fix
Install Node.js inside WSL with nvm, which the project says works through WSL, and put it first.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash3Verify
Open a new terminal; node must resolve to your home folder.
command -v nvm
nvm install --lts
which nodeConfirmed by github.com
How do I stop it coming back?
- Install developer tools inside WSL, and keep projects in the Linux filesystem.
- Check which -a before blaming the binary.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy stops because the predeploy lint step failed
Error: There was an error deploying functions
The predeploy hook in firebase.json runs npm run lint before every deploy, and a failing hook cancels the deploy.
3 causes, each with a fixBack end
fluent-ffmpeg cannot find the ffmpeg or ffprobe binary
Error: Cannot find ffprobe
fluent-ffmpeg does not bundle ffmpeg.
4 causes, each with a fix