pnpm login

别名:adduser

使用 npm 注册源进行身份验证。

pnpm login [--registry <url>] [--scope <scope>]

支持使用二维码进行网页登录,以及传统的用户名/密码验证。

Web-based login does not require an interactive terminal. Without a TTY, pnpm login prints the authentication URL (skipping the QR code and the prompt to open the URL in a browser) and polls the registry until the browser approval completes. 只有传统的用户名/密码登录方式在非交互式终端中仍会因 ERR_PNPM_LOGIN_NON_INTERACTIVE 错误而失败。

Since v12.13.0, web-based login prints the registry's npm-notice messages before the authentication URL. Some registries use them to show a verification code that you confirm in the browser.

The granted token is written to <pnpm config>/auth.ini. Since v12.1.0, --scope also routes that scope to the registry under the global registries setting in config.yaml.

From v12.1.0 to v12.15.0, the token was written to the _auth setting in the global config.yaml. There, an unscoped token also made its registry the default. Since v12.16.0 a login removes the token it replaces from _auth.

配置项#

--registry <url>#

用于身份验证的注册源。默认使用已配置的默认注册源。

--scope <scope>#

将凭据与指定范围关联。将使用该范围的注册源。

Since v12.1.0, a scope setting in a project's pnpm-workspace.yaml is ignored with a warning. A repository must not be able to choose the machine-wide route a later login writes. Pass --scope, set PNPM_CONFIG_SCOPE, or set the machine's default with:

pnpm config set --global scope @acme