# "401 Unauthorized" deploying to npm package registry

**URL:** <https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845>\
**Category:** Deployment\
**Tags:** npm\
**Created:** [January 14, 2020, 1:58pm UTC](https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845 "2020-01-14T13:58:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximelafarie](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/maximelafarie/32/3626_2.png) [@maximelafarie](https://travis-ci.community/u/maximelafarie)\
**Post date:** [January 14, 2020, 1:58pm UTC](https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845/1 "2020-01-14T13:58:10Z")

</div>

Like this post: [Support deploying to GitHub package registry](https://travis-ci.community/t/support-deploying-to-github-package-registry/4799), I can’t get how to deploy on NPM package registry. I got the following message: `You must be logged in to publish packages`.

What’s crazy is that before, I have the message:

```auto
Authenticate deployment
npm version: 6.13.4
Authenticated with API token 
~/.npmrc size: 33
$ npm config set registry "https://registry.npmjs.org"

```

So I assume I am logged in to npm.

Full CI output here: [https://travis-ci.org/maximelafarie/browizard/builds/636899450#L284](https://travis-ci.org/maximelafarie/browizard/builds/636899450#L284)  
Full Travis configuration: [https://travis-ci.org/maximelafarie/browizard/jobs/636899451/config](https://travis-ci.org/maximelafarie/browizard/jobs/636899451/config)

---

<div class="post-metadata">

**Author:** ![maximelafarie](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/maximelafarie/32/3626_2.png) [@maximelafarie](https://travis-ci.community/u/maximelafarie)\
**Post date:** [January 14, 2020, 2:23pm UTC](https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845/3 "2020-01-14T14:23:07Z")

</div>

It’s impossible since the log file is stored on the VM.

So I indeed got this: `cat: /home/travis/.npm/_logs/2020-01-14T13_44_59_979Z-debug.log: No such file or directory`

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [January 14, 2020, 3:08pm UTC](https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845/5 "2020-01-14T15:08:48Z")

</div>

Okay, looking at the log wasn’t needed after all.

The reason is `NPM_TOKEN` and `NPM_EMAIL` envvars are not set.

---

<div class="post-metadata">

**Author:** ![maximelafarie](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/maximelafarie/32/3626_2.png) [@maximelafarie](https://travis-ci.community/u/maximelafarie)\
**Post date:** [January 14, 2020, 3:21pm UTC](https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845/6 "2020-01-14T15:21:10Z")

</div>

This is strange because I effectively set them (but only for master branch):

 ![image](https://us1.discourse-cdn.com/flex015/uploads/travis_ci/original/2X/6/6575839a5e2e720308f33f138618bfcaac30744c.png)

---

<div class="post-metadata">

**Author:** ![maximelafarie](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/maximelafarie/32/3626_2.png) [@maximelafarie](https://travis-ci.community/u/maximelafarie)\
**Post date:** [January 14, 2020, 3:29pm UTC](https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845/7 "2020-01-14T15:29:31Z")

</div>

Okay so you are completely right. That was because (for a reason I don’t understand) I set my variables to be available on master only… Since the deploy job is triggered only on master pushes, I can’t get how this couldn’t work. Anyway, all works perfectly and I finally can deploy to npm! Thank you very much!

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [January 14, 2020, 6:29pm UTC](https://travis-ci.community/t/401-unauthorized-deploying-to-npm-package-registry/6845/8 "2020-01-14T18:29:52Z")

</div>

> [@maximelafarie](#):
>
> Since the deploy job is triggered only on master pushes, I can’t get how this couldn’t work.

[Travis CI - Test and Deploy with Confidence](https://travis-ci.org/maximelafarie/browizard/builds/636899450#L284) was a tagged build, not `master`, so the variables were not available to it.
