Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm publish Failed PUT 402

Tags:

npm

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.

like image 839
Joshua S Friedman Avatar asked Aug 22 '17 14:08

Joshua S Friedman


People also ask

What does lerna publish do?

Lerna is a monorepo manager for JavaScript projects. It helps you take a large codebase and split it into independently deployable packages. Lerna handles every step in the release process — from downloading dependencies, and linking packages together, to testing and publishing updated packages to the NPM registry.

What does NPM publish do?

Publishes a package to the registry so that it can be installed by name. By default npm will publish to the public registry. This can be overridden by specifying a different default registry or using a scope in the name, combined with a scope-configured registry (see package. json ).


3 Answers

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
like image 86
AlexStack Avatar answered Oct 22 '22 01:10

AlexStack


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

Then run npm publish --access public

like image 36
Dominic Avatar answered Oct 22 '22 00:10

Dominic


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.

like image 8
Benny Neugebauer Avatar answered Oct 22 '22 00:10

Benny Neugebauer