npm publish Failed PUT 402

Npm

Npm Problem Overview


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.

Npm Solutions


Solution 1 - Npm

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

Solution 2 - Npm

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

Then run npm publish --access public

Solution 3 - Npm

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoshua S FriedmanView Question on Stackoverflow
Solution 1 - NpmAlexStackView Answer on Stackoverflow
Solution 2 - NpmDominicView Answer on Stackoverflow
Solution 3 - NpmBenny NeugebauerView Answer on Stackoverflow