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.
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.
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.
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.
Error: EMFILE: too many open files, watch
EMFILE: fs.watch() limit exceeded
Error: Middleware next() called multiple times (next() invoked twice)
Express middleware next() called multiple times
Error: Worker failed to initialize (worker startup error)
Worker failed to initialize in Node.js
Error: EMFILE: too many open files, open 'file.txt'
EMFILE: too many open files
Error: cluster.fork() failed (cannot create child process)
cluster.fork() failed - Cannot create child process