簡體   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