'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.
Solution 1:[1]
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:[2]
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Dominic |
| Solution 3 | Benny Neugebauer |
