How to fix Error: spawn EACCES in Node.js
The spawn EACCES error occurs when Node.js attempts to spawn a child process but lacks execute permissions on the target executable. This commonly happens with binary files in node_modules or custom scripts that are missing the executable bit.
Quick fix
Fixes EACCES
ls -la /path/to/executable- Identify the missing executable permission
- Add execute permission to the binary
- Verify the permission change
- Reinstall node_modules if needed
ls -la /path/to/executableError: spawn EACCES
What this error means
The EACCES error code stands for "Error Access" and indicates that the operating system denied permission to execute a file. When Node.js child_process.spawn() attempts to launch an executable, the kernel checks if the calling process has execute permissions on that file. If the executable bit is not set, the spawn call fails immediately with EACCES. This is different from file read/write permissions—the executable bit is a separate permission that indicates the file is meant to be executed as a program. Without this bit set, the operating system will not allow execution, regardless of other permissions.
Typical symptoms
- Error: spawn EACCES appears in your console or logs
- Child process spawn() calls fail at runtime
- Package CLI commands fail (e.g., npm scripts that invoke binaries)
- Build tools or test runners fail when trying to spawn subprocesses
- The error occurs specifically on Linux/macOS (less common on Windows)
- Manual execution of the same file works with sudo
Common causes
- The target executable file is missing the executable (x) permission bit on Linux/macOS
- Files extracted from archives or git without preserving execute permissions
- Binaries installed in node_modules that lost execute permissions during transfer/copy
- Custom shell scripts or executables created without proper chmod settings
- File permission issues after npm install or yarn install in certain environments
- WSL (Windows Subsystem for Linux) mounting issues with Windows NTFS filesystems
How to fix "Error: spawn EACCES"
Check if the target file has execute permissions using:
ls -la /path/to/executableLook for the 'x' flag in the permission string. For example:
- -rwxr-xr-x (good - executable)
- -rw-r--r-- (bad - missing executable bit)
Use chmod to add execute permissions:
chmod +x /path/to/executableFor executables in node_modules (e.g., Next.js bin):
chmod +x node_modules/.bin/nextOr recursively for all binaries in a package:
chmod -R u+x node_modules/package-name/binConfirm the executable bit is now set:
ls -la /path/to/executableThe permission string should now include 'x', such as -rwxr-xr-x.
If the error affects multiple node_modules binaries, reinstall them:
rm -rf node_modules package-lock.json
npm installThis ensures all binaries are installed with correct permissions. Alternatively, use:
npm ciwhich respects the lock file and is more reliable for CI environments.
Verify that the child process spawns successfully:
const { spawn } = require('child_process')
const child = spawn('./your-executable', ['arg1', 'arg2'])
child.on('error', (err) => {
console.error('Spawn error:', err)
})
child.on('exit', (code) => {
console.log('Process exited with code:', code)
})If no error event fires, the spawn succeeded.
Advanced notes
WSL and NTFS mounting issues: If you're running Node.js in WSL and your project is on a Windows NTFS mount, file permissions behave differently. NTFS doesn't have Unix-style execute bits. To fix, move your project to the WSL filesystem (typically under /home/username) or use WSL-specific mount options.
Git and execute permissions: If you commit executables to git but they lose the execute bit when checked out, configure git to preserve permissions:
git config core.filemode true
git update-index --chmod=+x scripts/your-script.shDocker and node_modules: When copying node_modules into a Docker image, execute permissions are preserved by default with COPY. However, if you manually install packages inside the container, ensure the Dockerfile runs npm install (not copying pre-built node_modules from your local machine).
CI/CD environments: In automated pipelines, always run npm ci instead of npm install to ensure deterministic builds. However, if you encounter EACCES in CI even with npm ci, explicitly add permissions in your build script before running child processes.
Frequently asked questions
- What does "EACCES" mean?
- The EACCES error code stands for "Error Access" and indicates that the operating system denied permission to execute a file. spawn() attempts to launch an executable, the kernel checks if the calling process has execute permissions on that file. If the executable bit is not set, the spawn call fails immediately with EACCES.
- How do I fix "EACCES"?
- The spawn EACCES error occurs when Node.js attempts to spawn a child process but lacks execute permissions on the target executable. This commonly happens with binary files in node_modules or custom scripts that are missing the executable bit.
- What causes "EACCES"?
- The target executable file is missing the executable (x) permission bit on Linux/macOS Files extracted from archives or git without preserving execute permissions Binaries installed in node_modules that lost execute permissions during transfer/copy
- Is the "EACCES" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚Node.js Official Documentation
- 📖Node.js Child Process API - Error Event Documentation(Official Docs)
- 🐙
- 📖npm - Resolving EACCES Permissions Errors(Official Docs)
- 📝