LoginSignup
7
6

More than 1 year has passed since last update.

npm audit fixでエラーの解決法

Posted at

エラー内容

  found 1 high severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

上記は、パッケージをインストールした時に生じたエラー内容。
レベルがhighの脆弱性が1個あると記載されています。

解決方法

1.セキュリティーの内容確認

npm audit

npm auditのコマンドで詳細内容を確認

┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Code Injection                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ pac-resolver                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=5.0.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ firebase-tools                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ firebase-tools > proxy-agent > pac-proxy-agent >             │
│               │ pac-resolver                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1784                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 1 high severity vulnerability in 1222 scanned packages
  1 vulnerability requires manual review. See the full report for details.

上記の問題内容を見ていきます。
この例だとPathfirebase-tools > proxy-agent > pac-proxy-agent > │
pac-resolver
pac-resolverに脆弱性があるといことになります。

npm audit fix

npm audit fixと入力しても解決しなかったため、手動で解決する方法をまとめます。

2.修正方法

修正対象ファイル:package-lock.json

編集前
"requires": {
        "agent-base": "^6.0.0",                            
        "debug": "4",                                                
        "http-proxy-agent": "^4.0.0",               
        "https-proxy-agent": "^5.0.0",            
        "lru-cache": "^5.1.1",                            
        "pac-resolver": "^4.1.0",                      
        "proxy-from-env": "^1.0.0",                  
        "socks-proxy-agent": "^5.0.0"               
      },

Path を参照に対象箇所を特定
対象の"pac-resolver": "^4.1.0","pac-resolver": "^5.0.0"に変更。
"requires":{}の中身の "pac-resolver": "^5.0.0" 以外を削除

編集後
"requires": {                         
        "pac-resolver": "^5.0.0"        
      },

3.node_modulesの削除と再インストール

rm -rf node_modules/
npm install

4.エラーなしの確認

npm audit

エラー項目が0になっていることを確認

結果
121 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6