Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm publish gives "unscoped packages cannot be private"

Tags:

npm

I want to publish a normal, public package to npm. When I do npm publish I get:

npm ERR! publish Failed PUT 400 npm ERR! code E400 npm ERR! unscoped packages cannot be private : my-package 
like image 892
mb21 Avatar asked Nov 21 '18 21:11

mb21


People also ask

How do I make NPM packages private?

On the npm website, go to the package page. On the package page, click Admin. Under "Package Access", select "Is Package Private?" Click Update package settings.

What happens with npm publish?

When you run npm publish , npm bundles up all the files in the current directory. It makes a few decisions for you about what to include and what to ignore. To make these decisions, it uses the contents of several files in your project directory.


2 Answers

It appears that (as of November 2018), you have to do:

npm publish --access public 

This tells the npm registry that you want your package to be downloadable by everyone. This used to be the default, and from the documentation still should be, so probably this is just a bug in npm. There is some more, not very well written documentation about scoped/unscoped and public/private packages.

Instead of using --access, you can also add the setting to your package.json, as seen in @smnbbrv's answer below. But if I'm right an this is just a bug, you may want to just use --access as a temporary workaround.

like image 83
mb21 Avatar answered Oct 28 '22 23:10

mb21


With all the credits to @mb21 and his solution there is a small addition to his answer.

The proposed

npm publish --access public 

works perfectly. However it is not always possible to make it work within the CI environment, e.g. when you use semantic-release. The proper solution there would be using the very same access parameter but inside your package.jsons publishConfig (btw this also makes it easier to publish manually in the future):

{   "name": "...",   ...   "publishConfig": {     "access": "public"   } } 

And now you can use it within CI tools or simply

npm publish 

It costed me some time to figure this out, so I hope it saves some time for the future readers.

like image 40
smnbbrv Avatar answered Oct 29 '22 01:10

smnbbrv