Gotcha with `npm run` and extra arguments in Powershell

Aperta Adatta ai principianti
#2,081 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
markdown, powershell
Ambito
documentation

Direzione di ricerca

Trova la pagina della documentazione che spiega come passare argomenti agli script eseguiti con npm run, quindi leggi le indicazioni sugli script dipendenti dalla piattaforma menzionate nell’issue. Aggiungi una spiegazione concisa specifica per PowerShell ed esempi delle forme aggiuntive con --. Il lavoro è completato quando i lettori possono identificare il comportamento di PowerShell e vedere come passare gli argomenti allo script.

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

Descrizione

This might be worth documenting. NPM has the abililty to take extra arguments and pass them on to the underlying script that is configured in package.json. So npm run lint -- --fix, when in package.json it refers to eslint . becomes eslint . --fix.

So far so good, until one uses Powershell. In Powershell -- means "end of arguments" so anything that comes after it, is taken by NPM, not by the script, resulting in that warning:

npm warn Unknown cli config "--fix". This will stop working in the next major version of npm.

The easiest fix is to add more dashes:

npm run lint -- -- --fix

So that one of them survives, NPM sees it, and passes it on to the script.
Alternatively:

npm run lint '--' --fix

To be clear: this is Powershell only. CMD is unaffected, just like other shells probably.

The documentation currently says something quite cryptic about platform dependency when running scripts, and while platform specifics are not NPM's fault, I think it'd be useful to a lot of people who are caught out by this, to mention an obvious oddball.

Lingua principale
MDX
Stelle
743
Fork
4.3k
Merge medio
5g 11h
PR unite (30g)
2

Preparare l'ambiente

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 npm/documentation

Tutte le issue di npm/documentation

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.