簡體   English   中英

無法安裝我發布到 GCP 中的 npm 注冊表的范圍包

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

我將幾個 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包。 我已經嘗試創建全新的包、指定版本、重置身份驗證令牌,但由於某種原因我仍然無法下載包。

如果有幫助,我的 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]

原來這不是 GCP 特定問題,而是發布到 GCP 時的 Yarn Berry 問題。 正在生成的 tarballURL 使用截斷的注冊表 URL,這就是我在嘗試安裝軟件包時收到 404 的原因。 此處提出了對此的修復。 https://github.com/yarnpkg/berry/pull/3513

我有一個類似於這個的錯誤。

我完成了整個存儲庫創建過程並創建了一個新項目來測試包。

當我嘗試npm install my-package時,出現了 404 錯誤。

經過一些測試后,我發現我在將使用該包的項目中也需要.npmrc文件。 對某些人來說這似乎是顯而易見的,但我不知道。

將返回的配置設置添加到 Node.js 項目中的 .npmrc 配置文件。 此文件通常與 package.json 位於同一目錄中。

確保將這些設置包含在您發布的包的 Node.js 項目中,以及將從您的 npm 存儲庫安裝依賴項的項目。

為 npm 設置身份驗證

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM