Joshua S Friedman
Joshua S Friedman

Reputation: 743

npm publish Failed PUT 402

Working on a course that is having me go through a Bash tutorial. I am stuck on the part where the code is asking me to publish my code so far. My instructions are as follows:

 What good is a package manager without packages?  

 Not very good.  

 Luckily, that is not a problem for npm, because it's very easy for all  
 npm users to publish their modules and share them with the world.  

 Packages get into the registry by using the `npm publish` command.  

 Try it now. There's not much to it.  

 (Make sure you're still in the right project directory, though.  If you  
 publish something by mistake, you can remove it, but there's no guarantee  
 that no one saw it in the meantime.)  

 Then run `how-to-npm verify` when you're done.

My code was:

jsf2008:~/workspace/dev (master) $ npm publish
npm ERR! publish Failed PUT 402
npm ERR! code E402
npm ERR! You must sign up for private packages : @jsf2008/quit
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2017-08-22T14_44_29_746Z-debug.log
jsf2008:~/workspace/dev (master) $ 

I am quite lost here. I can't even find Error PUT 402 anywhere. Any help would be greatly appreciated.

Upvotes: 74

Views: 24396

Answers (4)

Abhigyan
Abhigyan

Reputation: 385

In my case the reason was that my package name was scoped i.e. it had a supericium, for exmaple: @supericium/package-name (or @pryansh/react-audio-gear).

But the catch here is, that you can use a supericium to prefix your package-name only if you have an organization's account on npmjs.com and as I didn't had it so a workaround was to remove supericium.

// BEFORE
{
  "name": "@pryansh/react-audio-gear",
  "version": "1.0.0",
  ...
// AFTER 
{
  "name": "react-audio-gear",
  "version": "1.0.0",

Upvotes: 1

Benny Code
Benny Code

Reputation: 54802

You can solve the problem by adding the following to your package.json file:

package.json

"publishConfig": {
  "access": "public"
}

The publishConfig value manages the visibility of your package. If you define "public" access, then your package can be downloaded by everyone from the npm registry.

If you define "restricted" access, then consumers of your package have to add a .npmrc file to their own package in order to set an access token:

.npmrc

always-auth=true
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

Note: You don't need the .npmrc file when you use "public" access.

Upvotes: 24

nanobar
nanobar

Reputation: 66355

First create the org: https://www.npmjs.com/org/create

Then run npm publish --access public

Upvotes: 15

AlexStack
AlexStack

Reputation: 17381

You're using NPM Scoped packages. They are private by default which requires paying NPM for a private account. If your package is public, you can use the --access=public flag like this:

npm publish --access=public

Upvotes: 167

Related Questions