我将几个 npm 包发布到托管在 GCP 中的私有 npm 注册表中,我可以看到注册表中的所有版本。但是我无法下载该软件包,因为安装命令会引发 E404。
NPM 在尝试下载页面时抛出一个通用的 404 错误:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://europe-north1-npm.pkg.dev/[Project]/@[scope]/[packagename]/-/@[scope]/[packagename]-0.1.0.tgz
npm ERR! 404
npm ERR! 404 '@[scope]/[packagename]@https://europe-north1-npm.pkg.dev/[Project]/@[scope]/[packagename]/-/@[scope]/[packagename]-0.1.0.tgz' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
打开要解析的 url 会返回此错误:
{"error":"Permission \"artifactregistry.repositories.downloadArtifacts\" denied on resource \"projects/[Project]/locations/europe-north1/repositories/@[scope]\" (or it may not exist)"}
{"error":"Unmatched scope name: \"\" != \"@[scope]\""}
另外,我检查了一下,我的帐户实际上确实具有 downloadArtifacts 角色。我无法弄清楚为什么它无法解析 URL,因为使用相同的配置我能够发布甚至运行npm view
包。我尝试过创建全新的包、指定版本、重置身份验证令牌,但由于某种原因我仍然无法下载包。
如果有帮助,我当前的 .npmrc 文件如下所示:
registry:https://registry.npmjs.org/=true
@[scope]:registry=https://europe-north1-npm.pkg.dev/[project]/[repo name]/
//europe-north1-npm.pkg.dev/[project]/[repo name]/:_authToken=[gcp auth token]
//europe-north1-npm.pkg.dev/[project]/[repo name]/:always-auth=true
//registry.npmjs.org/:_authToken=[npm auth token]