th0r/npm-upgrade

Unable to use npm-upgrade on private registry - error E401 authorization required

Closed this issue · 1 comments

Hi, I have set in the .npmrc of my progect the authentication to my private registry //private_registry.example.com/:_authToken=${NPM_TOKEN} and in the .env file NPM_TOKEN="MY_SECRET_NPM_TOKEN" .

I have also the authentication setted in the global .npmrc in C:\Users\myusername with //private_registry.example.com/:_authToken="MY_SECRET_NPM_TOKEN"

Infact I can run npm install without problem, but when I run npm-upgrade I get this error:

HttpErrorAuthUnknown: Unable to authenticate, need: Basic, Bearer

at C:\Users\...\node_modules\npm-upgrade\node_modules\npm-registry-fetch\check-response.js:113:17
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async viewMany (C:\Users\...\node_modules\npm-upgrade\node_modules\npm-check-updates\lib\package-managers\npm.js:136:18)
at async viewOne (C:\Users\...\node_modules\npm-upgrade\node_modules\npm-check-updates\lib\package-managers\npm.js:119:18)
at async latest (C:\Users\...\node_modules\npm-upgrade\node_modules\npm-check-updates\lib\package-managers\npm.js:272:20)
at async getPackageVersionProtected (C:\Users\...\node_modules\npm-upgrade\node_modules\npm-check-updates\lib\versionmanager.js:403:22)
at async C:\Users\...\node_modules\npm-upgrade\node_modules\p-map\index.js:57:22

{
  headers: [Object: null prototype] {
    server: [ 'nginx/1.18.0' ],
    date: [ 'Fri, 01 Jul 2022 07:26:01 GMT' ],
    'content-type': [ 'application/json; charset=utf-8' ],
    'content-length': [ '82' ],
    connection: [ 'keep-alive' ],
    'x-powered-by': [ 'verdaccio/4.11.0' ],
    'access-control-allow-origin': [ '*' ],
    'www-authenticate': [ 'Basic, Bearer' ],
    etag: [ 'W/"52-tcacakHnqE02WGK7MdceFfe1RVE"' ],
    vary: [ 'Accept-Encoding' ],
    'x-fetch-attempts': [ '1' ]
  },
  statusCode: 401,
  code: 'E401',
  method: 'GET',
  uri: 'https:///private_registry.example.com/@somepackage',
  body: {
    error: 'authorization required to access package @somepackage'
  },
  pkgid: '@somepackage'
}

Nevermind, solved by creating a .bashrc file in my home directory C:\Users\myusername with export NPM_TOKEN="MY_SECRET_NPM_TOKEN" as suggested here.