Home > Enterprise >  Can't install a scoped package I published to a npm registry in GCP
Can't install a scoped package I published to a npm registry in GCP

Time:10-01

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]

CodePudding user response:

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

  • Related