Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8898

npm audit fixで解決しないとき

$
0
0

随分古いバージョンのパッケージを使っていたシステムで、node.jsをアップデートをしたときに

found 98 vulnerabilities (39 low, 13 moderate, 46 high)in 10622 scanned packages
  94 vulnerabilities require semver-major dependency updates.
  4 vulnerabilities require manual review. See the full report for details.

のような文言が出力されましたので、その対応を行います。

大体の場合は『npm audit fix --force』をすれば解決するようですが、今回は一部上手くいかないものがあったので、直接ファイルをイジイジして治すことにします。

(この辺はあまり自信がないので、もしかしたら間違えてるかもです)

どのパッケージが問題なのか調べる

まずは、問題の原因であるパッケージの確認を行います。

$ npm audit
=>┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ lodash                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in>=4.17.12                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ kouto-swiss                                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ kouto-swiss > prefiks > lodash                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1065                            │
└───────────────┴──────────────────────────────────────────────────────────────┘

こんな表示になるかと思います。

今回の私の場合だと、lodashなるパッケージのバージョンに問題があったようです。

どうやら Patched inの欄で指定されているバージョンにlodashを変更すれば解決するようです。

では、今入っているlodashのバージョンを確認してみます。

$ npm ls lodash
=> 
willjekylltemplate@1.0.0 /home/misato/Documents/Blogs/for-misato-fans
├─┬ browser-sync@1.9.2
│ ├─┬ dev-ip@0.1.7
│ │ └── lodash@4.17.12
│ ├─┬ easy-extender@2.3.4
│ │ └── lodash@4.17.15 
│ ├─┬ glob-watcher@0.0.7
│ │ └─┬ gaze@0.5.2
│ │   └─┬ globule@0.1.0
│ │     └── lodash@4.17.12
├─┬ grunt@0.4.5
│ ├─┬ findup-sync@0.1.3
│ │ └── lodash@4.17.12
│ ├─┬ grunt-legacy-util@0.2.0
│ │ └── lodash@4.17.12
│ └── lodash@4.17.12
└─┬ kouto-swiss@0.11.14
  └─┬ prefiks@0.3.3
    └── lodash@2.4.2 <=こいつが原因

npm auditでは、lodashの推奨バージョンは >=4.17.12になっていましたが、npm ls lodashで見てみると、ひとつだけ 2.4.2となっています。

普通はnpm audit fixで全てバージョンを調整してくれる?みたいなんですが、なぜかひとつだけバージョンが変更されなかったようです。

とりあえず、こいつを直します。

package-lock.json でバージョンを修正

package-lock.jsonで"lodash": "2.4.2"を検索すると、下記のような感じでヒットしました。

"requires":{"accord":"0.12.0","gulp-util":"3.0.8","lodash":"2.4.2","replace-ext":"0.0.1","stylus":"0.54.7","through2":"0.6.5"}

これを npm audit で調べた推奨バージョンに書き換える↓

"requires":{"accord":"0.12.0","gulp-util":"3.0.8","lodash":"4.17.12","replace-ext":"0.0.1","stylus":"0.54.7","through2":"0.6.5"}

後は、下記のコマンドを実行する。

$ sudo rm-r node_module
  => node_moduleの削除

$ npm install

私の環境では、これで解決しました!!

(と言いつつ、結局各パッケージのバージョンアップは諦めて、nodeのバージョンを下げたのですが・・・ソレはまた別の話ですな)

誰かの参考になれば幸いです。


Viewing all articles
Browse latest Browse all 8898

Trending Articles