I am getting 404 error while running "npm publish"

7.5k Views Asked by At

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/"
  }
}
4

There are 4 best solutions below

4
On

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

"publishConfig": {
    "registry":"https://npm.pkg.github.com"
},
0
On

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

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

0
On

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.

2
On

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.