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:
- Login to my google account (
gcloud auth application-default login
) - Run
gcloud artifacts print-settings npm \ --project=[my-project]\ --repository=[my-repo] \ --location=us-east1 \ --scope=@[my-scope]
- Pasting the output of the previous step in the
.npmrc
file located in the root of the project. - Refreshing the access token to GCP (
npx google-artifactregistry-auth ./.npmrc
) - 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:
- Executing steps 1-4 mentioned above
- 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!
2条答案
按热度按时间jslywgbw1#
我只是有这个问题的几天,解决办法很简单,不使用Yarn当出版。就是这样。
我不知道yarn的哪一部分导致了这个问题,但基本上它忽略了.npmrc,导致tarball指向错误的存储库,如果你运行
yarn info
,你可以检查它。所以当发布到GCP工件注册表时,应该使用npm publish
代替。liwlm1x92#
In both setting up authentication for npm and Managing Node.js packages , Obtaining an access token section the command used is
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:
It could be written as
If you are not sure where your file is you can run
npm config ls -l | grep config
as explained hereAlso 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.