首頁·終端機命令

npm audit

套件與執行環境

用法

npm audit [fix] [--audit-level=<level>]

報告已安裝依賴中已知的安全漏洞;fix --force 會升到會破壞相容的大版本,而藏在開發依賴深處的警告往往根本修不了。

常用選項

選項含義
fixupgrade what it can inside your version ranges
fix --forceallow breaking major upgrades to clear a report
--audit-level=highonly fail on high and above
--omit=devignore dev-only dependencies
--jsonmachine-readable report
--dry-runshow the plan without changing anything

範例

npm audit

lists known vulnerabilities in the installed tree

npm audit fix

upgrades the ones that fit your ranges

npm audit fix --force

may install major versions that break your build

問題永遠是什麼裝到哪裡:裝進這個專案,還是裝到整台機器上。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. npm audit 是做什麼的?

報告已安裝依賴中已知的安全漏洞;fix --force 會升到會破壞相容的大版本,而藏在開發依賴深處的警告往往根本修不了。

Q. 怎麼寫?

npm audit [fix] [--audit-level=<level>] —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 6 個,完整列表在 man npm。這條命令屬於套件與執行環境。

相關命令

man 手冊: man npm-audit