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.6
ornpm
but with pnpm8.6.6
(and node20.3.0
) we get:I did some tests:
//gitlab.domain.com/api/v4/projects/:_authToken=AUTH_TOKEN
and this fixed the issue//gitlab.domain.com/api/v4/packages/npm/:_authToken=AUTH_TOKEN
this brings a new resolving issue. I guess no match between@team-software:registry=xxx
and 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_TOKEN
issued 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.13
it was working just fine.I’ve upgraded to
v7.14.1
and with the same.npmrc
I started getting:Downgrading to
7.13
worked 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
pnpm
should just work exactly likenpm
from 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
_authToken
entry but including:443
in the second one. Keep both.I found that duplicating
_authToken_
line with port:443
worked for me, but I think its perhaps a separate issue.I got into to the situation like this:
:443
in the URL so I suspect that could have something to do with the error_authToken
line to your.npmrc
config.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
pnpm
because of this for a long time. My situation:.npmrc
pnpm i
Any 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
env
like 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.x
was 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.npmrc
github 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
_authToken
for 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 publish
works fineaws codeartifact login ...
okpnpm install @my-scope/my-package
fail 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 import
works 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
:443
in the tarballGET
URL but not in theregistry
URL.@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/settings
On 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_TOKEN
should be able to access the desired package.For further reference, here is my
.npmrc
file 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 pnpm
instead 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.
pnpm
uses thenerf-dart
package. When theuri
of the registry is passed it’shttps://npm.pkg.github.com/statianzo/
npm
(6) uses its own implementation withinnpm-registry-fetch
https://github.com/npm/npm-registry-fetch/blob/d8df0b193b34dad4627db52259322f0dbf9257d2/auth.js#L49-L57
The passed url is
https://npm.pkg.github.com/statianzo
Notice no trailing slash. It matters when getting passed to
url.resolve
The above is with this
.npmrc
(no trailing slash):