npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

401 Unauthorized When Publishing Scoped Public Package

I’m unable to publish a new package to my organization’s scope.

I’m the owner of the org.

I’m trying to lerna publish from CI

circle config for the job contains:

- run:
  name: Authenticate with registry
  command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

error in CI:

lerna info auto-confirmed 
lerna info execute Skipping GitHub releases
lerna info git Pushing tags...
lerna info publish Publishing packages to npm...
lerna info Verifying npm credentials
lerna http fetch GET 200 https://registry.npmjs.org/-/npm/v1/user 631ms
lerna http fetch GET 200 https://registry.npmjs.org/-/org/bennyp/package?format=cli 153ms
lerna WARN lifecycle Skipping root "prepublish" because it has already been called
lerna http fetch PUT 401 https://registry.npmjs.com/@apollo-elements%2feslint-config 122ms
lerna ERR! E401 You must be logged in to publish packages.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! root@ publish: `lerna publish --message 'chore: release new versions' "--yes"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the root@ publish script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/circleci/.npm/_logs/2019-03-01T07_04_45_030Z-debug.log
Exited with code 1

I also get, when running lerna publish from-package on my dev machine, despite being logged in
lerna ERR! E401 You must be logged in to publish packages.

I tried manually npm publish for that specific package, but it also fails:

Logged in as bennyp on https://registry.npmjs.org/.
 > ~/D/apollo-elements > master > packages/eslint-config $ npm publish --access=public 
npm notice 
npm notice 📦  @apollo-elements/eslint-config@1.0.2
npm notice === Tarball Contents === 
npm notice 745B  package.json
npm notice 498B  CHANGELOG.md
npm notice 3.7kB index.js    
npm notice 1.1kB LICENCE.md  
npm notice === Tarball Details === 
npm notice name:          @apollo-elements/eslint-config          
npm notice version:       1.0.2                                   
npm notice package size:  2.5 kB                                  
npm notice unpacked size: 6.0 kB                                  
npm notice shasum:        31766a7e4fc50997f24ca7253077032df2722cf2
npm notice integrity:     sha512-vBf/xRLrbQMr4[...]zvB/PKwgrbtVg==
npm notice total files:   4                                       
npm notice 
npm ERR! code E401
npm ERR! 401 Unauthorized - PUT https://registry.npmjs.com/@apollo-elements%2feslint-config - You must be logged in to publish packages.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bennyp/.npm/_logs/2019-03-01T07_29_04_818Z-debug.log

That was after I deleted ~/.npmrc, then ran npm logout and npm login


What does npm whoami actually say?


> ~/D/apollo-elements > master $ npm whoami
bennyp
> ~/D/apollo-elements > master $ lerna publish from-package                                                                                                                                                                                                                                                      2662ms
info cli using local version of lerna
lerna notice cli v3.13.1
lerna info versioning independent

Found 1 package to publish:
 - @apollo-elements/eslint-config => 1.0.4

? Are you sure you want to publish these packages? Yes
lerna info publish Publishing packages to npm...
lerna info Verifying npm credentials
lerna http fetch GET 200 https://registry.npmjs.org/-/npm/v1/user 1148ms
lerna http fetch GET 200 https://registry.npmjs.org/-/org/bennyp/package?format=cli 1012ms
lerna http fetch PUT 401 https://registry.npmjs.com/@apollo-elements%2feslint-config 1061ms
lerna ERR! E401 You must be logged in to publish packages.

Oddly enough, I was able to publish from a different laptop, but not from my home computer or from CI