How to fix 404 error when installing npm package from GCP artifact registry with yarn?

bihw5rsg  于 2022-12-13  发布在  Yarn
关注(0)|答案(2)|浏览(235)

I'm having an issue with installing an NPM package from GCP.
I was able to upload the package to the artifact registry of GCP by doing the following steps:

  1. Login to my google account ( gcloud auth application-default login )
  2. Run
    gcloud artifacts print-settings npm \ --project=[my-project]\ --repository=[my-repo] \ --location=us-east1 \ --scope=@[my-scope]
  3. Pasting the output of the previous step in the .npmrc file located in the root of the project.
  4. Refreshing the access token to GCP ( npx google-artifactregistry-auth ./.npmrc )
  5. Run yarn publish
    My .npmrc file looks like this:
@[my-scope]:registry=https://us-east1-npm.pkg.dev/[my-project]/[my-repo]/
//us-east1-npm.pkg.dev/[my-project]/[my-repo]/:_authToken="[auth-token]"
//us-east1-npm.pkg.dev/[my-project]/[my-repo]/:always-auth=true

However, when I try to install the package on another project by:

  1. Executing steps 1-4 mentioned above
  2. Run yarn add @[my-scope]/[my-package]
    I get an 404 error. Looks like yarn is looking for the package in the default registry:
error An unexpected error occurred: "https://registry.yarnpkg.com/@[my-scope]/@[my-pacakge]/-/@[my-scope]/[my-package]-0.0.1.tgz: Request failed \"404 Not Found\"".

I simply followed the steps mentioned in the installation instructions in GCP but somehow it's not working.
I encountered a similar issue in this post: Can't install a scoped package I published to a npm registry in GCP but this not the exact error I get.
I would appreciate any help regarding this issue.
Thanks in advance!

jslywgbw

jslywgbw1#

我只是有这个问题的几天,解决办法很简单,不使用Yarn当出版。就是这样。
我不知道yarn的哪一部分导致了这个问题,但基本上它忽略了.npmrc,导致tarball指向错误的存储库,如果你运行yarn info,你可以检查它。所以当发布到GCP工件注册表时,应该使用npm publish代替。

liwlm1x9

liwlm1x92#

In both setting up authentication for npm and Managing Node.js packages , Obtaining an access token section the command used is

npx google-artifactregistry-auth

In the same section there is a note that explains how to add flags if you need to change the path of the .npmrc file.

**Note:**If you need to store your repository settings and credentials in .npmrc files other than the defaults, you can run the credential helper with additional flags.
--repo-config is the .npmrc file with your repository settings. If you don't specify this flag, the default location is the current directory.
--credential-config is the path to the .npmrc file where you want to write the access token. The default is your user .npmrc file.

Instead of:

npx google-artifactregistry-auth ./.npmrc

It could be written as

npx google-artifactregistry-auth --repo-config=pathto/.npmrc --credential-config=pathto/.npmrc

If you are not sure where your file is you can run npm config ls -l | grep config as explained here
Also check you are specifying the correct .npmrc path if it is different than the default registry as shown in Configuring npm and confirm you are trying to install a package from the Node.js package repository with the correct scope, package, tag or version to be completely explicit.

相关问题