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

Kar*_*ari 13 npm .npmrc

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

我有一个执行以下操作的 .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)    
}});
Run Code Online (Sandbox Code Playgroud)

当它第一次在 $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..
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢

Ahm*_*gdy 28

我想你之前可能已经运行过 vsts-npm-auth 并且在你的主目录的 .npmrc 中隐藏了令牌,它不再有效,你可能会尝试使用 -F 来强制获取新令牌。

  • 没有什么比无用的错误消息更重要的了。感谢@Ahmed 使用 -F 为我工作 (4认同)

小智 10

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

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