简体   繁体   English

vsts-npm-auth 存在代码 1,输入不是有效的 Base-64 字符串

[英]vsts-npm-auth exists with code 1, the input is not a valid Base-64 string

I have configured my project to use private Azure DevOps feed through.npmrc file.我已将我的项目配置为使用私有 Azure DevOps feed through.npmrc 文件。

I have a.js script that does the following:我有一个执行以下操作的 .js 脚本:

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.当它第一次在 $env:USERPROFILE.npmrc 文件下创建 .npmrc 文件时,一切都很好。

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."文档说,如果 -F 标志“不存在或为假,则目标配置文件中的现有令牌只有在接近或过期时才会被替换”。 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 -R -C ' + npmrc_location'时会遇到以下错误:

 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.我最好的猜测是它试图读取 .npmrc 文件的内容。

Does anyone know why this can happen and what would be a good solution for it?有谁知道为什么会发生这种情况以及什么是好的解决方案?

Thanks谢谢

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.我认为您之前可能已经运行过 vsts-npm-auth 并将令牌隐藏存储在您主目录的 .npmrc 中,并且它不再有效,您可以尝试使用 -F 强制获取新令牌。

@Ahmed has the right idea. @Ahmed 有正确的想法。 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

If this helper is defined in the npm script which is more convenient like below,如果这个助手是在 npm 脚本中定义的,这样更方便,如下所示,

{
  "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强制令牌获取可以通过run传递参数来完成

npm run registryAuth -- -F

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM