npm version9以降でユーザ名・パスワードでログインする場合は --auth-type=legacy が必要

レジストリを指定してnpmパッケージをインストールしようとした時に遭遇したエラー。 ちなみにこのレジストリは、ユーザ名・パスワードでのログインを想定している。

$ npm login --registry=https://<registry>/
npm notice Log in on https://<registry>/
npm ERR! code ENYI
npm ERR! Web login not supported

npm ERR! A complete log of this run can be found in:

npmドキュメントを確認するとこんなことが書いてあった。

https://docs.npmjs.com/cli/v9/commands/npm-login#description

When using legacy for your auth-type, the username and password, are read in from prompts.

ユーザ名・パスワードをプロンプトから読み込んで認証するときは、--auth-type=legacy をつける必要があった。

npm install - npm login not allowing login to github - Stack Overflow によると、 npmのバージョン9以降だとこのオプションが必要らしい。

$ npm login --auth-type=legacy --registry=https://<registry>/
npm notice Log in on https://<registry>/
Username: xxxxx
Password: 

これでログインできた。