npmやnpxでCannot read properties of null (reading 'pickAlgorithm') が発生する

Cannot read properties of null (reading 'pickAlgorithm')エラーは node.js や npm のアップデート後に発生することがあります。解決するにはキャッシュをクリアします。

エラーの発生例

npxコマンドでエラーが発生している様子
npxコマンドでエラーが発生している様子
>npx eslint --init
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Need to install the following packages:
  eslint
Ok to proceed? (y) y
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm ERR! Cannot read properties of null (reading 'pickAlgorithm')

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\    \AppData\Local\npm-cache\_logs\2022-07-04T08_25_33_976Z-debug-0.log

解決方法

次のコマンドを実行し、npmのキャッシュをクリアします。
npm cache clear --force
npmキャッシュクリア
npmキャッシュクリア
キャッシュクリア後、再度エラーの発生したコマンドを実行します。
再実行
再実行

検証環境