`ng serve` crashes with `EMFILE: too many open files, watch` on macOS when `preserveSymlinks` is enabled (22.2 regression)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 48/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- angular, node.js, typescript
- Domaine
- build-system, devtools
Piste de recherche
Start by reading setupWatcher and createWatcher, especially the followSymlinks branch that selects chokidar, and compare the watcher behavior described for @parcel/watcher. Reproduce on macOS with preserveSymlinks: true and more than 4096 workspace directories. Done means ng serve and watch builds stay running without the EMFILE crash in that setup.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Command
serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
22.1.9
Description
Since 22.2.0, ng serve (and any watch build) crashes on macOS right after the first successful build when the build target sets preserveSymlinks: true and the workspace contains more than 4096 directories outside node_modules.
setupWatcher passes preserveSymlinks on as followSymlinks, and createWatcher then always picks chokidar over @parcel/watcher:
if (options?.polling || options?.followSymlinks) {
return createChokidarWatcher(options);
}
Chokidar 5 calls fs.watch once per directory and file under the workspace root. On macOS, Node reports EMFILE as soon as one process holds more than 4096 directory watches: 4096 fs.watch calls on directories work, 4097 fail. File watches do not count towards this (50,000 worked), and ulimit -n has no influence: the crash reproduces with the hard limit at unlimited.
The error is emitted on the FSWatcher without a listener, so the dev server process exits.
In our application (about 1,250 source directories plus the packages it imports from node_modules, which chokidar also watches whole) the dev server made 33,703 fs.watch calls before crashing. With 22.1.9 and watchpack the same workspace needs 4. We depend on preserveSymlinks because plugin frontends are symlinked into src/.
Minimal Reproduction
On macOS:
npx @angular/[email protected] new emfile-repro --defaults --skip-git
cd emfile-repro
node -e "for (let i = 0; i < 4200; i++) fs.mkdirSync('many/d' + i, { recursive: true })"
npx ng config projects.emfile-repro.architect.build.options.preserveSymlinks true
npx ng serve
The server prints its local URL and exits a moment later with the error below. It keeps running with preserveSymlinks unset, or with 3000 directories instead of 4200.
Exception or Error
Error: EMFILE: too many open files, watch
at FSWatcher._handle.onchange (node:internal/fs/watchers:267:21)
Emitted 'error' event on FSWatcher instance at:
at FSWatcher._handleError (node_modules/chokidar/index.js:558:18)
at NodeFsHandler._boundHandleError (node_modules/chokidar/handler.js:297:49)
at node_modules/chokidar/handler.js:144:9
at foreach (node_modules/chokidar/handler.js:76:9)
at fsWatchBroadcast (node_modules/chokidar/handler.js:143:5)
at FSWatcher.<anonymous> (node_modules/chokidar/handler.js:191:17)
at FSWatcher.emit (node:events:509:28)
at FSWatcher._handle.onchange (node:internal/fs/watchers:273:12) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
filename: null
}
Your Environment
Angular CLI : 22.2.2
Angular : 22.2.2
Node.js : 24.18.0
Package Manager : npm 11.16.0
Operating System : darwin arm64 (macOS 27.0.1)
@angular/build 22.2.2
@angular/cli 22.2.2
@angular/compiler-cli 22.2.2
typescript 6.0.3
Anything else relevant?
@parcel/watcher loads and subscribes fine on the same machine, so this is not the load-failure fallback. With preserveSymlinks off the dev server holds no fs.watch handles at all. Would it be possible to keep the parcel watcher for preserveSymlinks workspaces, or to limit chokidar to the files the build actually reports instead of the whole workspace root?
Workaround: pin @angular/build to 22.1.9, or run with --watch false.
- Langage dominant
- TypeScript
- Étoiles
- 27k
- Forks
- 11.8k
- Merge moyen
- 1 j 4 h
- PR mergées (30 j)
- 168
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de angular/angular-cli
-
area: @angular/cli
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
angular/angular-cli#34307 ·
Les mainteneurs répondent en général sous 1 jour
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverOuvertearea: @angular/build gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
angular/angular-cli#33955 ·
Les mainteneurs répondent en général sous 1 jour
-
area: @angular/cli gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
angular/angular-cli#33055 · 1 commentaire · 3 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
unit-test builder (Vitest): test bundle output is not deterministic, which defeats Vitest 5 `fsModuleCache`Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouvertearea: @angular/build
Difficulté 4/5 3-5 jours Accessibilité débutants 22/100
angular/angular-cli#34335 ·
Les mainteneurs répondent en général sous 1 jour
-
@angular/ssr: page under nested empty-path routes is prerendered without the modulepreload hints of its lazy chunks (regression since 19.1.6)Peut-être pris @alan-agius4 l’a pris il y a 1 jour. Ouvertearea: @angular/ssr
angular/angular-cli#34320 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de angular/angular-cli
Issues similaires
-
Add: VIVE TVOuverteapproved check:passed streams:add
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
iptv-org/iptv#55293 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Fission-AI/OpenSpec#2084 ·
Les mainteneurs répondent en général sous 2 jours
-
Contrib indemnité de départ à la retraite : faire le pont avec le simulateur sur la page génériqueOuverteP1
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
SocialGouv/code-du-travail-numerique#7561 ·
Les mainteneurs répondent en général sous 1 jour
-
beginner bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
hiero-ledger/hiero-sdk-js#4517 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
kubernetes-sigs/headlamp#7950 ·
Les mainteneurs répondent en général sous 3 jours