简体   繁体   中英

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. Yet I can't download the package since the install command throws an E404.

NPM throws a generic 404 Error when trying to download the page:

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:

{"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. 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. 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:

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. 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. A fix for this was proposed here. 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.

After some tests I discovered that I need the .npmrc file also in the project that will consume the package. 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. This file is usually in the same directory as 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.

Set up authentication for npm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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