The `google-artifactregistry-auth` module (currently at v3.5.0) provides command-line tools to configure npm and Yarn to authenticate with private npm repositories hosted in Google Cloud's Artifact Registry. It streamlines the process of obtaining and managing access tokens by automatically leveraging Google Application Default Credentials or the active `gcloud` login. The package sees a fairly active release cadence, with minor versions introducing features like Yarn support, flexible domain configurations, and token passing, indicating ongoing development and refinement. Its primary differentiator is the deep integration with Google Cloud's authentication mechanisms, making it the go-to solution for JavaScript package management within the Google Cloud ecosystem, especially for CI/CD pipelines and developer workstations. It's designed to simplify the typically complex setup of token-based authentication for private registries.
npm install google-artifactregistry-authVerified import paths — ran on the pinned version, not inferred.
Demonstrates the full flow for authenticating npm with a Google Artifact Registry private repository, from initial Google Cloud authentication to running the `google-artifactregistry-auth` CLI to configure `.npmrc`.
Update your scripts to use the `--repo-config` and `--credential-config` flags to explicitly define the paths for your repository settings and credential storage. For Yarn, use `--repo-config-yarn` and `--credential-config-yarn`.
If you require multiple distinct credentials for different Artifact Registry repositories, consider manual credential management or using separate npm/yarn configurations per project/context, or explore custom solutions for token management that do not rely on this module for multi-account scenarios.
Ensure `gcloud auth application-default login` or `gcloud auth login` has been executed, or that the `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key file before running the module.
Always explicitly specify `--repo-config` (or `--repo-config-yarn`) for the file containing your repository URL and `--credential-config` (or `--credential-config-yarn`) for where the token should be written to ensure predictable behavior, especially in CI/CD environments.
Run `gcloud auth login` or `gcloud auth application-default login` to authenticate, or set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of a service account key JSON file.
Verify that the path provided to `--credential-config` (or `--credential-config-yarn`) is correct and that the user running the command has write permissions to that file.
Re-run the `npx google-artifactregistry-auth` command to refresh the authentication token in your `.npmrc` or `.yarnrc.yml` file. Ensure your Google Cloud credentials are still valid.