vscode: askpass-main.js TypeError: Cannot read properties of undefined (reading 'replace')

Might already have a duplicate issue but I did not find one, so I am reporting this (again) here.

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version:
  • OS Version:
Version: 1.74.0-insider (user setup)
Commit: 1b1e2a2c5794df1f475976062c754651827634a9
Date: 2022-11-18T05:25:18.342Z
Electron: 19.1.3
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: Yes

Steps to Reproduce:

  1. Open a WSL2 project whose git remote url is ssh-based (not http-based)
  2. Make sure ssh-agent has no credential remembered (aka. the next ssh will require password prompt)
  3. Click the Commit button in vscode
  4. Shows an error dialog, whose git error output is:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file - -S
error: /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1
(()=>{"use strict";var e={4516:(e,s,r)=>{Object.defineProperty(s,"__esModule",{value:!0}),s.IPCClient=void 0;const t=r(8605);s.IPCClient=class{constructor(e){this.handlerName=e;const s=process.env.VSCODE_GIT_IPC_HANDLE;if(!s)throw new Error("Missing VSCODE_GIT_IPC_HANDLE");this.ipcHandlePath=s}call(e){const s={socketPath:this.ipcHandlePath,path:`/${this.handlerName}`,method:"POST"};return new Promise(((r,n)=>{const o=t.request(s,(e=>{if(200!==e.statusCode)return n(new Error(`Bad status code: ${e.statusCode}`));const s=[];e.on("data",(e=>s.push(e))),e.on("end",(()=>r(JSON.parse(Buffer.concat(s).toString("utf8")))))}));o.on("error",(e=>n(e))),o.write(JSON.stringify(e)),o.end()}))}}},5747:e=>{e.exports=require("fs")},8605:e=>{e.exports=require("http")}},s={};function r(t){var n=s[t];if(void 0!==n)return n.exports;var o=s[t]={exports:{}};return e[t](o,o.exports,r),o.exports}var t={};(()=>{var e=t;Object.defineProperty(e,"__esModule",{value:!0});const s=r(5747),n=r(4516);function o(e){console.error("Missing or invalid credentials."),console.error(e),process.exit(1)}!function(e){if(!process.env.VSCODE_GIT_ASKPASS_PIPE)return o("Missing pipe");if(!process.env.VSCODE_GIT_ASKPASS_TYPE)return o("Missing type");if("https"!==process.env.VSCODE_GIT_ASKPASS_TYPE&&"ssh"!==process.env.VSCODE_GIT_ASKPASS_TYPE)return o(`Invalid type: ${process.env.VSCODE_GIT_ASKPASS_TYPE}`);if("fetch"===process.env.VSCODE_GIT_COMMAND&&process.env.VSCODE_GIT_FETCH_SILENT)return o("Skip silent fetch commands");const r=process.env.VSCODE_GIT_ASKPASS_PIPE,t=process.env.VSCODE_GIT_ASKPASS_TYPE,i="https"===t?e[2]:e[3];let c,a,p;"https"===t&&(c=e[4].replace(/^["']+|["':]+$/g,"")),"ssh"===t&&(/passphrase/i.test(i)?a=e[6].replace(/^["']+|["':]+$/g,""):(c=e[6].replace(/^["']+|["':]+$/g,""),p=e[15])),new n.IPCClient("askpass").call({askpassType:t,request:i,host:c,file:a,fingerprint:p}).then((e=>{s.writeFileSync(r,e+"\n"),setTimeout((()=>process.exit(0)),0)})).catch((e=>o(e)))}(process.argv)})();var n=exports;for(var o in t)n[o]=t[o];t.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})})();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

TypeError: Cannot read properties of undefined (reading 'replace')
    at /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:1709
    at /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:1966
    at /home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:1982
    at Object.<anonymous> (/home/username/.vscode-server-insiders/bin/1b1e2a2c5794df1f475976062c754651827634a9/extensions/git/dist/askpass-main.js:1:2088)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module
fatal: failed to write commit object

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 15
  • Comments: 38 (5 by maintainers)

Most upvoted comments

Has anybody figured out a workaround yet?

wow, I just figured it out, answering it by myself:

If you run into this problem, make sure you manually add the identity (your private ssh key) to ssh-agent like this:

$ ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Note: The --apple-use-keychain option stores the passphrase in your keychain for you when you add an SSH key to the ssh-agent. If you chose not to add a passphrase to your key, run the command without the --apple-use-keychain option.

Run this command after every system reboot and commits will work in VS Code. I guess this whole problem only occurs if you have multiple SSH keypairs in the default location ~/.ssh/id_* and somehow VS Code only adds the first best to the ssh-agent, so usually ~/.ssh/id_rsa. So, somehow VS Code doesn’t seem to respect the user.signingkey global git config. Just guesses… hope this brings you guys further.

При клонировании репозиторий VS Code пишет “или” содержит отпечаток важных" и ответов " да" и “нет”. Когда “Да” >, окно запускает снова .

TypeError: Cannot read properties of undefined (reading 'replace')
    at c:\Users\Andry\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass-main.js:1:1703
    at c:\Users\Andry\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass-main.js:1:1922
    at c:\Users\Andry\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass-main.js:1:1938
    at Object.<anonymous> (c:\Users\Andry\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass-main.js:1:2044)
    at Module._compile (node:internal/modules/cjs/loader:1165:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1220:10)
    at Module.load (node:internal/modules/cjs/loader:1035:32)
    at Module._load (node:internal/modules/cjs/loader:876:12)
    at c._load (node:electron/js2c/asar_bundle:5:13343)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

Снимок экрана 2023-03-25 012835

Проблема решилась установкой Git Access для Windows и командой

https://github.com/Microsoft/Git-Credential-Manager-для-Windows

git config --global core.sshCommand "SSH_ASKPASS=\"C:\Program Files\Git\mingw64\libexec\git-core\git-askpass.exe\" DISPLAY=localhost:0.0 ssh"

Руководство: https://predvoditelev.ru/notes/git-windows-ssh-passphrase-gui/

По какой-то причине Askpass не используется вместе с Git для Windows.

The solution to work without additional installations for me was to enter the command in Git Bash git config --global core.sshCommand "SSH_ASKPASS=\"C:\Program Files\Git\mingw64\libexec\git-core\git-gui--askpass\" ssh"

The field of this earned cloning and synchronization with the Git repository through the VS Code interface. My .gitconfig file now looks like this:

[core]
	editor = \"C:\\Users\\<user>\\AppData\\Local\\Programs\\Microsoft VS Code\\bin\\code\" --wait
	sshCommand = SSH_ASKPASS=\"C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-gui--askpass\" ssh
[user]
	name = <name>
	email = <email>
[difftool "sourcetree"]
	cmd = "'' "
[mergetool "sourcetree"]
	cmd = "'' "
	trustExitCode = true
[credential]
	helper = wincred

The sshCommand = SSH_ASKPASS=\"C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-gui--askpass\" line was required to solve this problem. ssh-agent and ssh-add ~/.ssh/id_ed25519 did not help with this problem.

FYI I am signing my commit using my ssh key, not GPG key