LoginSignup
5
3

More than 1 year has passed since last update.

npm installlをすると出てくる警告の解消

Posted at

初めまして、現在ReactーReduxを勉強中のものです。

今回は、「npm install」をすると出てくる警告がうざかったので解消しようと思いました。

警告とは何?

npm installとかすると出てくるやつです。

# コマンド
$ npm install --save --force @mui/material 

# 以下警告文

npm WARN using --force Recommended protections disabled.

added 7 packages, removed 26 packages, changed 33 packages, and audited 612 packages in 6s

15 packages are looking for funding
  run `npm fund` for details

21 vulnerabilities (6 moderate, 14 high, 1 critical)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

「vulnerabilities」とは脆弱性です。
パッケージの中に脆弱性があると、正規表現とかで攻撃されるらしいです。

消し方

手順1

まず、警告文に書いてあるとおり、npm audit fixをしてみます。

npm WARN audit fix tar@4.4.8 node_modules/fsevents/node_modules/tar

# 中略

added 23 packages, removed 5 packages, changed 31 packages, and audited 630 packages in 8s

22 packages are looking for funding
  run `npm fund` for details

# npm audit report

glob-parent  <5.1.2
Severity: high
Regular expression denial of service in glob-parent - https://github.com/advisories/GHSA-ww39-953v-wcq6
fix available via `npm audit fix`
node_modules/watchpack-chokidar2/node_modules/glob-parent
  chokidar  1.0.0-rc1 - 2.1.8
  Depends on vulnerable versions of glob-parent
  node_modules/watchpack-chokidar2/node_modules/chokidar
    watchpack-chokidar2  *
    Depends on vulnerable versions of chokidar
    node_modules/watchpack-chokidar2
      watchpack  1.7.2 - 1.7.5
      Depends on vulnerable versions of watchpack-chokidar2
      node_modules/watchpack

4 high severity vulnerabilities

To address all issues, run:
  npm audit fix

「4 high severity vulnerabilities」、つまり、「4件の高い脆弱性」がまだ残ってるらしいです。

手順2

こちらの記事を参考にしました。

「npm-check-updates」というパッケージを用いました。
パッケージの最新バージョンを調べて、package.jsonを書き換えてくれるらしいです。

  1. npm install -g npm-check-updatesでインストール
  2. ncuで現在の状況を確認
  3. ncu -uでpackage.jsonを最新バージョンに書き換え
  4. npm installで最新バージョンをインストール
# 最新バージョンをインストール
npm install

# ログ
added 89 packages, removed 332 packages, changed 170 packages, and audited 366 packages in 21s

39 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

脆弱性がなくなりました:clap:

まとめ

npm audit fixと「npm-check-updates」で警告文をなくすことができました。

警告文はうざったいので、さっさと取り除きたいですね。

5
3
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
5
3