Handle broken symlinks gracefully during file tracing

Aperta
#601 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

@Harshalj2108 ci sta già lavorando.

Dal 16/7/2026.

  • #602 di @Harshalj2108 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, node.js
Ambito
devtools, tooling

Direzione di ricerca

Inizia con src/fs.ts e src/node-file-trace.ts, seguendo nodeFileTrace fino a realpath e ai percorsi delle voci di directory che chiamano stat. Confronta questi percorsi con _internalReadlink e _internalStat, quindi riproduci lo scenario del symlink non valido su Node.js. Il lavoro è completato quando il tracing continua dopo ENOENT e la destinazione non valida è assente da fileList.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Description

When @vercel/nft traces dependencies in an environment containing broken symlinks
(symlinks whose target does not exist), the tracing process throws an unhandled
ENOENT error and aborts entirely.

Steps to Reproduce

  1. Create a broken symlink in the system (e.g., /etc/alternatives/which.sl1.gz
    pointing to a non-existent target)
  2. Run nodeFileTrace() on an entry file whose dependency chain resolves through
    that directory (e.g., via a binary that references /usr/bin/which →
    /etc/alternatives/which)
  3. The trace fails with: Error: ENOENT: no such file or directory, stat '/etc/alternatives/which.sl1.gz'

Expected Behavior

Broken symlinks should be skipped gracefully (similar to how _internalReadlink
already handles ENOENT by returning null). The trace should continue and
simply not include the broken symlink target in the output fileList.

Actual Behavior

The entire trace aborts with an unhandled ENOENT error, preventing any output
from being generated.

Environment

  • @vercel/nft version: 0.29.2
  • Node.js: 20.x
  • OS: Linux (CI container based on CentOS/Alpine with stale symlinks in
    /etc/alternatives)

Analysis

In src/fs.ts, _internalStat correctly returns null for ENOENT. However,
the realpath() method in src/node-file-trace.ts recursively resolves paths
by calling readlink → resolve → realpath again. During this recursion,
when the resolved path traverses a directory that contains broken symlinks,
subsequent operations on adjacent files (like glob-based asset emission or
shared library detection) may attempt to stat those broken symlinks through
a code path that does not handle the null/ENOENT return gracefully.

Suggested Fix

Ensure that any code path that calls stat() or processes directory entries
during tracing handles broken symlinks (stat returning null) by skipping
the entry rather than propagating the error.

Lingua principale
JavaScript
Stelle
1.7k
Fork
191
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel/nft

Tutte le issue di vercel/nft

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.