NPM Issue

NPM Errors are sometimes opaque. Yesterday, while working on a personal npm package, I faced the following issue while publishing using usual command:

npm publish

Output!

npm ERR! publish Failed PUT 400
npm ERR! code E400
npm ERR! unscoped packages cannot be private : my-package

What a random bug!

Fix

After looking a bit on the Internet, it seems that npm teams changed default npm publish command default arguments. You now have to specify that you want your package to be public. According to official documentation, we have two alternatives:

Explicitely add –access public argument to our publish command:

npm publish --access public

Or, you can edit your package.json file:

{
 "name": "my_package",
 "version": "1.0.0",
 // ...
 "publishConfig": {
   "access": "public"
 }
}
package.json

And then:

npm publish

That should fix it!