pnpm: Cannot authenticate to Github repo during the installation process
When trying to install my packages using a private registry, pnpm goes in error.
I think I know what’s going on.
Doing the same via npm works fine because it installs the dependencies that are not in scope from the npm registry and installs the scoped dependencies (the private ones) from the github registry. I could verifying it by checking its package-lock.json
On the other hand, pnpm tries to install ALL the dependencies from one single registry, which is github.
pnpm version: 5.9.3
Code to reproduce the issue:
Code inside .npmrc
registry=https://npm.pkg.github.com/{SCOPE}
I can’t give the information of the log because it contains sensitive information.
Expected behavior:
It should install all the packages.
Actual behavior:
ERROR GET https://npm.pkg.github.com/{SCOPE}/bootstrap: Unauthorized - 401
No authorization header was set for the request.
These authorization settings were found:
//npm.pkg.github.com/:_authToken={TOKEN}
Additional information:
Changing .npmrc to the following works fine
{SCOPE}:registry=https://npm.pkg.github.com/{SCOPE}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 27
- Comments: 80 (22 by maintainers)
Commits related to this issue
- fix: don't add unnecessary trailing slash ref pnpm/pnpm#2933 — committed to pnpm/normalize-registry-url by zkochan 3 years ago
- fix: don't add trailing slash to registry URLs ref #2933 — committed to pnpm/pnpm by zkochan 3 years ago
- fix: don't add trailing slash to registry URLs ref #2933 close #4034 — committed to pnpm/pnpm by zkochan 3 years ago
- fix: don't add trailing slash to registry URLs (#4032) ref #2933 close #4034 — committed to pnpm/pnpm by zkochan 3 years ago
- fix: don't add trailing slash to registry URLs ref #2933 ref #4034 ref #4032 — committed to pnpm/pnpm by zkochan 3 years ago
- fix: missing auth token in registries with paths included (#7337) close #5970 close #2933 --------- Co-authored-by: Zoltan Kochan <z@kochan.io> — committed to pnpm/pnpm by nachoaldamav 7 months ago
We got private package resolving issues too and the last valid version is
7.13.6.Some context: we use a Gitlab instance on premise and our .npmrc look like:
We try to install a library hosted on this gitlab registry:
"@team-software/v-components": "0.0.96"This configuration works with
pnpm<=7.13.6ornpmbut with pnpm8.6.6(and node20.3.0) we get:I did some tests:
//gitlab.domain.com/api/v4/projects/:_authToken=AUTH_TOKENand this fixed the issue//gitlab.domain.com/api/v4/packages/npm/:_authToken=AUTH_TOKENthis brings a new resolving issue. I guess no match between@team-software:registry=xxxand thexxx:_authToken=token//gitlab.domain.com/api/v4/:_authToken=AUTH_TOKEN, this is working (but doesn’t follow what gitlab recommend to use for npm).Final:
My understanding is to resolve the package there is a first match on
gitlab.domain.com/api/v4/packages/npm/then a download issued on the url resultgitlab.domain.com/api/v4/projects/. Before the headerAUTH_TOKENissued on the first match was forwarded on the “related download” even if there was an uri mismatch?Just a guess without diving too much how things are working, if someone has more context about this 🙏
I have the following
.npmrc:And til
pnpm@7.13it was working just fine.I’ve upgraded to
v7.14.1and with the same.npmrcI started getting:Downgrading to
7.13worked wellI am not sure why you all try to include the owner in the registry URL. The docs suggest to use:
Though this seems to work with npm, so I guess it should works with pnpm as well.
I have the identical issue, this does seem like a long time. ~/.npmrc
then…
@zkochan FYI I had this config in my global
.npmrc:which works with
npm install, but breakspnpm install. The following changes fixed it:But I think
pnpmshould just work exactly likenpmfrom the same configuration…So, 2 issues it seems:
/is required before:_authToken=${GITHUB_USER}in this case)I think this will work for you:
Duplicating the
_authTokenentry but including:443in the second one. Keep both.I found that duplicating
_authToken_line with port:443worked for me, but I think its perhaps a separate issue.I got into to the situation like this:
:443in the URL so I suspect that could have something to do with the error_authTokenline to your.npmrcconfig.I was using pnpm version 7.9.3 and 7.27.1 to test this.
Any progress on this please? Haven’t been able to use
pnpmbecause of this for a long time. My situation:.npmrcpnpm iAny advice would be highly appreciated.
+1 7.13.6 works and the 7.28.0 didnt work
Alrighty, so I’ve managed to get everything working in GitHub Actions. Below is a list of what I’ve done to get it functional.
I listened to the advice of @brybicki-cyferd https://github.com/pnpm/pnpm/issues/2933#issuecomment-1298586488 and their example with regards to implementing the registry and accounting for the tarball URL:
Which afterwards gave me an error as I wasn’t able to use a secret in the usual sense. So I instead opted to just implement it in an
envlike so:This was enough to get the correct authorisation to finally install my private packages.
This was hard to navigate on a few accounts:
node 14.xwas a hindrance as well. This prompted me to make an abrupt upgrade to our node version(we’re readying a big upgrade) to try and get things working.This was my experience with the getting things going and so I hope that this sheds some light on problems other people might be having. Thanks a bunch @zkochan for their patience and my haranguing about using pnpm.
I’m also open to improving the way I structure my workflows. So if anyone has tips or wants to point some stuff out, then please feel free.
Workflows config:
Rollback pnpm version to 7.11.0 worked to me.
I just had to configure pnpm as well (with
pnpm config set) rather than just having.npmrcgithub workflow:
.npmrc:
Good news for CodeArtifact users, from AWS’ side this problem has been solved. Quoting a CodeArtifact operation notification all customers who use it got:
Just complementing what @tlehtimaki said, on my team, we had problems with per project
.npmrc. They still get those errors even if they add the_authToken.The solution was by also adding the
_authTokenfor port 443 in the root level.npmrc(for UNIX users it may be located at~/.npmrc. Or check it here: https://pnpm.io/cli/config)Same problem with aws and CodeArtifact
aws codeartifact login ...okpnpm publishworks fineaws codeartifact login ...okpnpm install @my-scope/my-packagefail withpnpm --version 7.25.0
npm 8 works…
Also having this issue on 7.22.0 in combination with gitlab. Rolled back to 7.13.0 which is working fine.
ERR_PNPM_FETCH_404 GET <repo-url> Not Found - 404 No authorization header was set for the request.
I can confirm a regression between 7.13 and 7.14, as well. If I had to take a guess, it would due to how we do auth headers now: https://github.com/pnpm/pnpm/commit/804de211ea299804b9f7d6857eeb93b618856452
I am unsure how to make pnpm to log HTTP requests/responses to dig in further.
Any news?
Edit: Okay, so right after I commented I was about to give up on pnpm but a took another look at npmrc and removed the owner from the github repo url and now
pnpm importworks for me 🎉 So I hadand now I have
And this seems to work on my side.
See if my solution for CodeArtifact can help you guys - https://github.com/pnpm/pnpm/issues/5561#issuecomment-1298565447.
Quite likely given you have
:443in the tarballGETURL but not in theregistryURL.@kraikov I got this to work inside GH Actions by adding the desired repository to the list of allowed action runners. This list is located inside your package settings page. Take this URL as reference to locate this page:
https://github.com/USERNAME/packages/npm/PACKAGE_NAME/settingsOn this page, add the desired repository from where you want your GH Action runner to install your private package from.
Once that is done, the generated
secrets.GITHUB_TOKENshould be able to access the desired package.For further reference, here is my
.npmrcfile as well as my workflow file I used to test this:Alternatively, take a look at my testing repository: https://github.com/KuhlTime/pnpm-cannot-authenticate
I hope this will help you 🤞
Hey @zkochan, thanks for the quick reply:
Here is the log from the github actions:
And here is the script:
and here’s the content of .npmrc
I’ve tried to use my own generated PAT with the correct permissions instead of
GITHUB_TOKEN- the same result.I’ve also tried to install pnpm using
npm install -g pnpminstead of using the actions. Again - the same result.Update: hardcoding the PAT instead of getting it from env works
Suspected reason for not sending auth: the resulting “nerf dart” made by pnpm is different than npm’s because of a trailing slash.
pnpmuses thenerf-dartpackage. When theuriof the registry is passed it’shttps://npm.pkg.github.com/statianzo/npm(6) uses its own implementation withinnpm-registry-fetchhttps://github.com/npm/npm-registry-fetch/blob/d8df0b193b34dad4627db52259322f0dbf9257d2/auth.js#L49-L57
The passed url is
https://npm.pkg.github.com/statianzoNotice no trailing slash. It matters when getting passed to
url.resolveThe above is with this
.npmrc(no trailing slash):