# macOS: Error: EMFILE: too many open files, watch / ulimit: setrlimit failed: invalid argument

**Code:** `Too many open files (macOS limits)` · **Category:** macOS · **Seen on:** macOS, Node.js

A process hit the low default per-process open-file limit on macOS (256 soft in shells), common with file watchers and big builds.

## Meaning

Raise the shell limit: `ulimit -n 10240` (hard limits via `launchctl limit maxfiles`). Reduce watchers (exclude `node_modules` from watchers) and install Watchman for React Native/Jest. Persistent limits use a LaunchDaemon plist for `launchctl limit`.

## Common causes

- Default soft limit 256
- File watchers (webpack, Jest, Metro) on huge trees
- Many sockets/connections
- Leaking file handles
- Node `fs.watch` on node_modules

## Quick fix

1. `ulimit -n 10240` before running the tool
2. `brew install watchman` for Metro/Jest
3. Find leaks with `lsof -p PID | wc -l`

## Detailed fix by platform

### macOS

1. `ulimit -n && launchctl limit maxfiles`

## How to diagnose

1. **Limit** — ulimit -n?
2. **Watchers** — Large tree?
3. **Leak** — lsof count?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/macos/too-many-open-files-maxfiles)
