LoginSignup
0
0

More than 1 year has passed since last update.

npmコマンド実行時に大量に発生したnode-sassのnpm ERR解消

Last updated at Posted at 2023-06-10

はじめに

npm install実行時に、node-sassの警告文とエラー文が発生した。発生当時、かなりの行数に渡って警告・エラー文が表示され、それらを参考に解消を図ったものの、かなりの時間を要したため、備忘録として残す。諸事情により、パスを一部省略している。
プログラミング初心者であるため、思いつくことを片っ端から試した。解決に全く関係ないことを行っている場合もあると思われるが、あらかじめご了承願いたい。

環境

  • OS: Windows10
  • node: v18.15.0
  • npm: 9.5.0

以下、package.jsonの記載。

  • "node-sass": "^8.0.0",
  • "pinia": "^2.0.28",
  • "vue": "^3.2.45"

解決法(It works for me)

node-sassの再インストールで解決した。どうやら考えられる解決法が様々あるようなので、一概にこの方法がエラーの改善につながるわけではないが、本文を見る前に一度試してみると時間短縮になるかもしれない。
以下はnode-sassのアンインストールと、インストールのコマンドである。この順番で実行すると、node-sassの再インストールができる。

npm uninstall node-sass
npm install node-sass

環境依存で発生している可能性について

調査したところ、WindowsOSだと発生しやすいという記事を見かけた。私はMacOSのPCが手元になく、エラー状況の再現もできないため、真偽は定かではない。

エラー内容

以下はエラー文の詳細である。

npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic. 
 See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN cleanup Failed to remove some directories [
npm WARN cleanup   [
npm WARN cleanup     'C:\\work\\(省略)\\node_modules\\pinia',
npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\work\(省略)\node_modules\pinia\node_modules\vue-demi'] {       
npm WARN cleanup       errno: -4048,
npm WARN cleanup       code: 'EPERM',
npm WARN cleanup       syscall: 'rmdir',
npm WARN cleanup       path: 'C:\\work\\(省略)\\node_modules\\pinia\\node_modules\\vue-demi'
npm WARN cleanup     }
npm WARN cleanup   ],
npm WARN cleanup   [
npm WARN cleanup     'C:\\work\\(省略)\\node_modules\\node-sass',
npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\work\(省略)\node_modules\node-sass\test\fixtures\watcher\main\partials'] {
npm WARN cleanup       errno: -4048,
npm WARN cleanup       code: 'EPERM',
npm WARN cleanup       syscall: 'rmdir',
npm WARN cleanup       path: 'C:\\work\\(省略)\\node_modules\\node-sass\\test\\fixtures\\watcher\\main\\partials'
npm WARN cleanup     }
npm WARN cleanup   ],
npm WARN cleanup   [
npm WARN cleanup     'C:\\work\\(省略)\\node_modules',
npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir 'C:\work\(省略)\node_modules\node-sass\test\fixtures\watcher\sibling'] {
npm WARN cleanup       errno: -4048,
npm WARN cleanup       code: 'EPERM',
npm WARN cleanup       syscall: 'rmdir',
npm WARN cleanup       path: 'C:\\work\\(省略)\\node_modules\\node-sass\\test\\fixtures\\watcher\\sibling'
npm WARN cleanup     }
npm WARN cleanup   ]
npm WARN cleanup ]
npm ERR! code 1
npm ERR! path C:\work\(省略)\node_modules\node-sass
npm ERR! command failed

node-sassの再インストールでエラー解消ができなかった場合

以下では、私が試したもののエラーの改善に至らなかった際に行ったことを記している。node-sassの再インストールでエラー解消が見込めない場合に解決につながるかもしれないため、参考にしてほしい。

npmのキャッシュ削除

npmのキャッシュを削除する方法。以下のコマンドを実行するとキャッシュクリーンができる。

npm cache verify

うまくいかない場合、cache clean --forceでもキャッシュ削除ができるらしい。

npm cache clean --force

cache clean verify と cache clean --force の違いは、

  • verify:「キャッシュフォルダの内容を確認し、不要なデータをガベージコレクションし、キャッシュインデックスとすべてのキャッシュデータの整合性を確認する」
  • clean: 「キャッシュフォルダーからすべてのデータを削除」

とのこと。以下引用元リンク。
引用:キャッシュフォルダーからすべてのデータを削除

パッケージを最新バージョンへとバージョンアップ

警告文にあるパッケージを最新バージョンへとバージョンアップする。本記事のエラー内容を見ると、har-validator@5.1.5 はサポートが終了しているため、代替のライブラリを使うことや、@npmcli/move-file@1.1.2 は @npmcli/fs に移動していること、uuid@3.4.0 をv7.0以上にバージョンアップすること、request@2.88.2 でrequestの使用が非推奨になっていることが示されている。自分の環境でターミナルに表示されたエラー文や警告文から、必要なパッケージのアップデートを行うと解決する可能性がある。

node.jsの再インストール

node.jsを再インストールする方法。公式サイトからインストーラーに従ってインストールするか、以下の別記事を参考にnode.jsを再インストールしてほしい。なお、node.jsとnpmはバージョンをあわせないといけないようなので、注意してほしい。

node-modulesディレクトリの削除

npm installが成功した後に、npmコマンドでエラーが発生した場合、一度node-modulesのディレクトリを削除し、再度npm installを実行するとよいと考えられる。私はnpm install時にエラーが発生しているため、この方法を実際に試しているわけではないことを留意してほしい。

それでも解決しない場合

解決しない場合、以下の記事の内容で解消する可能性がある。私が試したわけではないため、詳細はリンクの記事を参考にしてほしい。

おわりに

今見てみるとnode-sassの名前が挙がった警告文がほとんどなので、最初の方に試すべきだった。プログラミング初学者にとって(当然私も含めて)大量の警告文やエラー文に拒否反応が出るのは仕方ないが、わざわざ文字に起こして警告してくれる親切さに甘えよう、という自戒。

参考文献

以下、本記事の作成にあたって参考にしたサイトである。本記事で解決に至らなかった場合は、リンクから詳細な内容を辿ってほしい。

0
0
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
0
0