Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Can't run npm install and can't even run npm whoami without errors using GitHub Packages #2758

Closed
joshuarobs opened this issue Feb 22, 2021 · 9 comments
Assignees
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@joshuarobs
Copy link

joshuarobs commented Feb 22, 2021

Current Behavior:

If I run these various commands, I get these errors. Everything seemed to be working fine a month ago and often if things broke, I'd typically look towards regenerating a github token and putting that into my ~/.npmrc file. This started from a few versions ago, around 7.4.3 I believe.

My goal is to have this work normally as usual: install public npm packages as you would without any additional configuration, yet be able to access private packages hosted on GitHub packages.

My .npmrc file in the project folder is:

registry=https://npm.pkg.github.com/joshuarobs

I regenerated a token in this url on GitHub: https://github.com/settings/tokens/ and I copied and pasted it into ~/.npmrc with the contents as follows:

//registry.npmjs.org/:_authToken=XXX
//npm.pkg.github.com/:_authToken=XXX
fund=false
// Running `npm whoami`
joshua@Joshuas-MBP fashion-app-cms-ts % npm whoami
npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/joshuarobs/-/whoami
npm ERR! 404 
npm ERR! 404  'whoami' 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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/joshua/.npm/_logs/2021-02-22T23_31_44_906Z-debug.log

Not sure why it would consider whoami as a package when clearly its a command.

Anyway, if I also try to run npm install I get a similar issue:

joshua@Joshuas-MBP fashion-app-cms-ts % npm install
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR!     https://www.npmjs.com/forgot
npm ERR! 
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR!     npm login

If I try to do as suggested, when I try to run npm login I get:

joshua@Joshuas-MBP fashion-app-cms-ts % npm login
npm notice Log in on https://npm.pkg.github.com/joshuarobs
Username: joshuarobs
Password: 
Email: (this IS public) XXX
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/joshuarobs/-/user/org.couchdb.user:joshuarobs
npm ERR! 404 
npm ERR! 404  'org.couchdb.user:joshuarobs' is not in the npm registry.
npm ERR! 404 This package name is not valid, because 
npm ERR! 404  1. name can only contain URL-friendly characters
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Not sure why I get an error like this, seeing as I entered my details properly and copied and pasted the token in properly.

Expected Behavior:

Everything should work as intended. npm whoami should give a simple result of the username/alias and npm install should install packages.

Steps To Reproduce:

  1. Create an .npmrc file locally in a nodejs project with contents: registry=https://npm.pkg.github.com/[MY_GITHUB_USERNAME]
  2. Create a new token at https://github.com/settings/tokens/ with permissions: repo, workflow and write:packages checked
  3. Create a ~/.npmrc and paste //npm.pkg.github.com/:_authToken=XXX
  4. Copy token that was created in step 2 and replace XXX with that
  5. Try to run npm whoami
  6. Try to install some packages with npm install

Environment:

  • OS: MacOS Big Sur 11.2.1
  • Node: 14.15.1
  • npm: 7.5.6
@joshuarobs joshuarobs added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Feb 22, 2021
@joshuarobs
Copy link
Author

Downgrading to 6.14.11 works for me.

I still get an error running npm whoami, but I can successfully install packages with npm install

@nlf
Copy link
Contributor

nlf commented Feb 24, 2021

you have your registry specified as https://npm.pkg.github.com/joshuarobs however i think the url you want is https://npm.pkg.github.com without the username as part of the path

this change makes the request to whoami be https://npm.pkg.github.com/-/whoami which is a valid url and succeeds.

this working in npm 6 i think is actually a bug in npm 6 where the path is being ignored..

@nlf nlf removed the Needs Triage needs review for next steps label Feb 24, 2021
@nlf nlf self-assigned this Feb 24, 2021
@bradydoll
Copy link

I'm running into this same issue after upgrading to v7.5.6 from v6.14.10.

GitHub repositories require the owner in the path, ex registry=https://npm.pkg.github.com/OWNER. This is documented in their configuration guide.

@leepowelldev
Copy link

For the login issue, see if this works (https://docs.github.com/en/packages/guides/configuring-npm-for-use-with-github-packages#authenticating-to-github-packages):

npm login --scope=@joshuarobs --registry=https://npm.pkg.github.com

@nlf
Copy link
Contributor

nlf commented Feb 25, 2021

I know those docs instruct you to append your username, but if you can try without it and let me know what that changes I'd appreciate it. If that works I'll make sure the docs are modified to reflect that

@o0x2a
Copy link

o0x2a commented Apr 22, 2021

I needed to add registry command line option to make it work

npm login --registry=https://npm.pkg.github.com

@nlf
Copy link
Contributor

nlf commented Apr 4, 2022

Closing due to age. If this is still a problem please feel free to reopen this issue, or create a new issue w/ steps to reproduce.

@nlf nlf closed this as completed Apr 4, 2022
@WarrenWongCodes
Copy link

Noting here if anyone had organizational issues after running the above steps. Ensure that your Personal Access token is authorized by your company as well.

@bradydoll
Copy link

I was able to resolve my issue by changing the syntax in the .npmrc file. Instead of registry=https://npm.pkg.github.com/OWNER, I changed it to @OWNER:registry=https://npm.pkg.github.com (the documentation on GitHub was also updated with this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

6 participants