繁体   English   中英

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

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

我已将我的项目配置为使用私有 Azure DevOps feed through.npmrc 文件。

我有一个执行以下操作的 .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)    
}});

当它第一次在 $env:USERPROFILE.npmrc 文件下创建 .npmrc 文件时,一切都很好。

文档说,如果 -F 标志“不存在或为假,则目标配置文件中的现有令牌只有在接近或过期时才会被替换”。 所以重新运行脚本作为我项目构建步骤的一部分应该没问题。

但是,有时在执行'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..

我最好的猜测是它试图读取 .npmrc 文件的内容。

有谁知道为什么会发生这种情况以及什么是好的解决方案?

谢谢

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

@Ahmed 有正确的想法。 我无法评论答案,但简而言之,您可以运行它来获取令牌:

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

如果这个助手是在 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": {
  }
}

强制令牌获取可以通过run传递参数来完成

npm run registryAuth -- -F

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

暂无
暂无

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

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