I am getting 404 error while running "npm publish"
Asked Answered
P

4

10

I am trying to publish a package to the npm registry. But when I hit the command npm publish I get this error.

npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.

> [email protected] prepublish .
> npm run build


> [email protected] build /home/suraj/Projects/bitandbang
> node build.js

npm notice 
npm notice πŸ“¦  [email protected]
npm notice === Tarball Contents === 
npm notice 1.1kB LICENSE     
npm notice 3.6kB bin/output  
npm notice 233B  bin/card.js 
npm notice 996B  package.json
npm notice 293B  README.md   
npm notice === Tarball Details === 
npm notice name:          imojha                                  
npm notice version:       1.0.0                                   
npm notice package size:  2.3 kB                                  
npm notice unpacked size: 6.2 kB                                  
npm notice shasum:        bb283ae5fe8aed311771f369866c13e24f1eb937
npm notice integrity:     sha512-Nzc+Ysmf4RgSi[...]XoT+OGYHNHoSQ==
npm notice total files:   5                                       
npm notice 
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.registry.github.com/imojha
npm ERR! 404 
npm ERR! 404  '[email protected]' 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!     /home/suraj/.npm/_logs/2020-10-24T14_54_01_996Z-debug.log

I have successfully run npm login. Then I am executing npm publish.

I have cloned this repo from GitHub and publishing to the npm. It's actually about creating npx card of your own name, like npx username. I am doing the same.

I have tried giving it a different package-name but couldn't make it. So, Could someone please tell me what I am doing wrong? Here is the package.json file.

{
  "name": "suraj-ojha",
  "version": "1.0.0",
  "description": "A personal card for Suraj Ojha (@suraj)",
  "main": "/bin/card.js",
  "bin": {
    "bitandbang": "./bin/card.js"
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:Suraez/npxcard.git"
  },
  "homepage": "https://bnb.im",
  "scripts": {
    "prepublish": "npm run build",
    "build": "node build.js",
    "dev": "npm run build && node ./bin/card.js",
    "lint": "standard",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "card",
    "npm",
    "npm card",
    "npx",
    "npx card",
    "business card"
  ],
  "author": "suraj Ojha",
  "license": "MIT",
  "files": [
    "bin/card.js",
    "bin/output"
  ],
  "devDependencies": {
    "boxen": "^2.1.0",
    "chalk": "^2.4.1",
    "standard": "^12.0.1"
  },
  "bugs": {
    "url": "https://github.com/bnb/bitandbang/issues"
  },
  "dependencies": {},
  "publishConfig": {
    "registry": "https://npm.registry.github.com/"
  }
}
Pseudocarp answered 24/10, 2020 at 15:14 Comment(6)
Don't you mean 404 error, not 403? – Marlysmarmaduke
Why would you republish someone else's package? That said, did you remember to actuall edit the package.json so that npm knows to publish it as your project? – Longcloth
i did. i tried putting different package name but no luck. – Pseudocarp
i am not trying to republish someone else's package or steal someone else's credit for their work. This registry or package helps you to build a so-called npx card and everybody is making their own with the help of this package and so am i. @Mike'Pomax'Kamermans – Pseudocarp
If this is your own project, and you followed the regular npm init procedure, with a regular npm login, then at the very least in addition to asking here on Stackoverflow ask the NPM folks what is going wrong because you're experiencing problems with their tool, and they are the primary authority on how things should work. SO is where you ask once you've tried all the obvious places the look/ask and found nothing. – Longcloth
#39115601 – Selfreliant
L
1

Update: I believe its caused from issues from the .npmrc in your home folder. Messing with the $HOME variable also seems to make it fail. Removing that file, and logging back into npm seems to fix the issue.

Beyond the answer though, Suraj Oberai your question is very well worded with all the necessary information, I don't think you deserve your downvotes.

I've published many npm packages, but this was the first time I had come across this issue myself. It was very strange as there was almost no difference between this one and previous packages I've published. I had to track down the issue by taking one of my working packages and (many useless publishes later) slowly convert it into my attempt that was causing the error, only to get to the point where literally nothing different between the projects. Nothing except the HOME Env variable of the shell.

This is definitely a bug with npm. It seems like the error above is the default error, so its possible my change might not solve this issue for you.

Libby answered 8/11, 2020 at 2:32 Comment(2)
thanks @jeff , that means a lot to me, I will try your proposed changes – Pseudocarp
Answer was significantly updated just now (FYI Suraj Oberai) – Libby
C
0

The publishConfig URL might be wrong. Can you try adding the publishConfig option in package.json:

"publishConfig": {
    "registry":"https://npm.pkg.github.com"
},
Crossjack answered 24/10, 2020 at 15:44 Comment(4)
I am not sure if the owner is really necessary. You can try it without its owner. :( – Amido
i did all these things, what the heck "username@version is not in npm registry" does it mean anyway ? – Pseudocarp
the package.json is shared after i changed the URL suggested by you. there seems to be a problem with npm/cli. i checked GitHub and the issue is still not resolved completely – Pseudocarp
Believe me, the problem still persists with that URL in my case. Why would I lie? – Pseudocarp
C
0

It worked for with this other registry (maybe they updated it?):

 "publishConfig": {
    "registry": "https://registry.npmjs.org/"
  }

Crest answered 16/8, 2021 at 0:45 Comment(0)
S
0

GitHub NPM registry is used for private packages. The package name has to be scoped. "name": "suraj-ojha" won't work for GitHub. It needs to be something like @suraj/ojha or @bnb/bitandbang (since that's your GitHub username and repo name).

If you don't intend to publish a private package and want to publish it to the public, remove the publishConfig section in package.json so npm publish uses the default public registry.

Sapers answered 17/10, 2022 at 5:31 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.