vsts-npm-auth exists with code 1, the input is not a valid Base-64 string
Asked Answered
B

4

20

I have configured my project to use private Azure DevOps feed through .npmrc file.

I have a .js script that does the following:

const { exec } = require('child_process');
const npmrc_location = ...
const commands = 
[    
    'npm install vsts-npm-auth --registry https://registry.npmjs.com --always-auth false --no-save',    
    'vsts-npm-auth -R -C ' + npmrc_location
];

exec(commands.join('&&'), (error) => {    
    if (error) {        
       console.log(error)    
}});

When it first creates the .npmrc file under $env:USERPROFILE.npmrc file, everything is fine.

The documentation says that if the -F flag is "absent or false, an existing token in the target configuration file will only be replaced if it is near or past expiration." So re-running the script as part of the building step of my project should be fine.

However, there are times when I run into the following error when 'vsts-npm-auth -R -C ' + npmrc_location' is executed:

vsts-npm-auth v0.41.0.0:
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters..

My best guess is that it tries to read the content of .npmrc file.

Does anyone know why this can happen and what would be a good solution for it?

Thanks

Byre answered 29/7, 2020 at 7:40 Comment(0)
S
62

i think you might have run the vsts-npm-auth before and got token hiddenly stored within the .npmrc at your home dir and it`s not valid anymore, you might try to use -F to force fetching a new token.

Snug answered 12/8, 2020 at 17:11 Comment(4)
Nothing like useless error messages. Thanks @Ahmed using -F worked for meMunguia
like a charm and leaves me feeling stupid. one would think i'd be used to it by now lolEnki
Thanks @Ahmed It's working for meLithea
Why can't i upvote twice ?Calefaction
S
21

@Ahmed has the right idea. I cannot comment on the answer, but in short you can run this to fetch the token:

vsts-npm-auth -config <path_to_npmrc_file> -F

Sudorific answered 31/8, 2020 at 19:14 Comment(0)
M
1

If this helper is defined in the npm script which is more convenient like below,

{
  "name": "my-app",
  "version": "0.0.1",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "start:dev": "ng serve",
    "build": "ng build",
    "registryAuth": "vsts-npm-auth -config .npmrc"
  },
  "dependencies": {
  },
  "devDependencies": {
  }
}

Force token acquisition can be done by passing argument through run

npm run registryAuth -- -F

Reference - https://www.npmjs.com/package/vsts-npm-auth

Mitigate answered 23/7, 2021 at 11:36 Comment(0)
D
1

In my case, the main .npmrc file was corrupted. I fixed it with following steps

  1. delete (or rename to .npmrc_backup) the .npmrc file located in route C:\Users<someuser> or equivalent linux path
  2. run your vsts-npm-auth command again
Deathtrap answered 17/3, 2022 at 20:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.