windows の npm 更新で EINVAL (invalid argument) エラーが発生したときの対処方法

npm でモジュールをインストールしていると以下のエラーに遭遇しました。

C:\WINDOWS\system32>npm install -g npm
npm ERR! code EINVAL
npm ERR! EINVAL: invalid argument, read
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xx\AppData\Roaming\npm-cache\_logs\2019-04-15T19_33_00_354Z-debug.log

これは既知のバグだそうです。以下の手順で更新ができます。

1. PowerShell のセキュリティポリシーを更新

PS C:\WINDOWS\system32> Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

2. npm-windows-upgrade という モジュールをインストールする。

PS C:\WINDOWS\system32> npm install --global --production npm-windows-upgrade

3. npm-windows-upgrade を実行して、npm を更新

PS C:\WINDOWS\system32> npm-windows-upgrade
npm-windows-upgrade v6.0.1
? Which version do you want to install? (Use arrow keys)
> 6.9.1-next.0
  6.9.0
  6.9.0-next.0
  6.8.0
  6.8.0-next.2
  6.8.0-next.1
  6.8.0-next.0
(Move up and down to reveal more choices)

バージョンを選択できますので、6.9.0 を選びました。

4. しかしインストールされたバージョンは 6.8.0

このブログを書いた時点の最新は6.9.0でしたので、6.9.0 を選択しましたが、インストールされたのは 6.8.0 でした。6.9.0 にアップデートするには、アンインストールしてインストールするしか無いようです。

You wanted to install npm 6.9.0, but the installed version is 6.8.0. A common reason is an attempted “npm install npm” or “npm upgrade npm”. As of today, the only solution is to completely uninstall and then reinstall Node.js. For a small tutorial, please see https://github.com/felixrieseberg/npm-windows-upgrade#usage. Please consider reporting your trouble to https://aka.ms/npm-issues.

具体的な方法は以下のページに記載されています。

https://github.com/felixrieseberg/npm-windows-upgrade#issues–support

自分の node バージョンもまだ v10.15.1 なので、インストールしなおそうかな。

5. 参考URL

https://npm.community/t/einval-invalid-argument-read/574/3

https://github.com/felixrieseberg/npm-windows-upgrade#upgrade-npm-on-windows

コメント

タイトルとURLをコピーしました