简体   繁体   English

无法安装我发布到 GCP 中的 npm 注册表的范围包

[英]Can't install a scoped package I published to a npm registry in GCP

I published several npm packages to a private npm registry hosted in GCP and I can see all versions in the registry.我将几个 npm 包发布到托管在 GCP 中的私有 npm 注册表,我可以在注册表中看到所有版本。 Yet I can't download the package since the install command throws an E404.但是我无法下载该软件包,因为安装命令会抛出 E404。

NPM throws a generic 404 Error when trying to download the page: 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.

Opening the url that is tring to resolve returns this error:打开要解析的 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]\""}

Additonally, I checked and my account does in fact have to downloadArtifacts role.另外,我查了一下,我的账户确实有downloadArtifacts的作用。 I can't figure out why it's unable to resolve the URL since with the same config I'm able to both publish and even run npm view the package.我不明白为什么它无法解析 URL,因为使用相同的配置我可以发布甚至运行npm view包。 I've tried creating brand new packages, specifying a version, resetting the auth token and yet for some reason I'm still unable to download packages.我已经尝试创建全新的包、指定版本、重置身份验证令牌,但由于某种原因我仍然无法下载包。

If it helps, my current.npmrc file looks like this:如果有帮助,我的 current.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]

Turns out this was not a GCP specific issue, but a Yarn Berry issue when publishing to GCP.原来这不是 GCP 特定问题,而是发布到 GCP 时的 Yarn Berry 问题。 The tarballURL that is being generated uses a truncated registry URL which is why i was getting a 404 when trying to install the package.正在生成的 tarballURL 使用截断的注册表 URL,这就是我在尝试安装软件包时收到 404 的原因。 A fix for this was proposed here.此处提出了对此的修复。 https://github.com/yarnpkg/berry/pull/3513 https://github.com/yarnpkg/berry/pull/3513

I had an error similar to this one.我有一个类似于这个的错误。

I did the entire repository creation process and created a new project to test the package.我完成了整个存储库创建过程并创建了一个新项目来测试包。

When I tried npm install my-package I got a 404 error.当我尝试npm install my-package时,出现了 404 错误。

After some tests I discovered that I need the .npmrc file also in the project that will consume the package.经过一些测试后,我发现我在将使用该包的项目中也需要.npmrc文件。 It may seem kind of obvious to some people but I didn't know.对某些人来说这似乎是显而易见的,但我不知道。

Add the returned configuration settings to the.npmrc configuration file in your Node.js projects.将返回的配置设置添加到 Node.js 项目中的 .npmrc 配置文件。 This file is usually in the same directory as package.json.此文件通常与 package.json 位于同一目录中。

Make sure that you include these settings in Node.js projects for packages that you publish as well as projects that will install dependencies from your npm repository.确保将这些设置包含在您发布的包的 Node.js 项目中,以及将从您的 npm 存储库安装依赖项的项目。

Set up authentication for npm 为 npm 设置身份验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM