Install Extension is broken for Visual Studio Code

Filed under: DevOps

Visual Studio Code has a bug for install-extension in version 1.15.1. code --install-extension ms-mssql.mssql will now result in the error below:

(node:13048) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: this._state.then is not a function
(node:13048) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This happens for all extensions installed via command line by package name. Installing the extension inside the UI works fine. This happened on an earlier version of Visual Studio Code and it has again appeared in version 1.15.1.

  • https://github.com/Microsoft/vscode/issues/32381
  • https://github.com/Microsoft/vscode/issues/33812

If you need to work around it, you can install the extensions as a vsix file from the command line. You could wrap the code below into a function that takes a package name and it will download the .vsix file and install on the command line.

$name = "publisher.package"

$pattern = "<script class=`"vss-extension`" defer=`"defer`" type=`"application\/json`">(.*?)<\/script>"
$regex = [regex]"(?m)$pattern"
$dom = (New-Object Net.WebClient).DownloadString("https://marketplace.visualstudio.com/items?itemName=$name");


  if($dom -and $dom -match $pattern) {
       $matches = $regex.Match($dom)
       $jsonText = $matches[0].Groups[1]

       $json = ConvertFrom-Json $jsonText

       $version = $Json.versions[0].version
       $parts = $name.Split(".")
       $publisher = $parts[0]
       $package = $parts[1]

       $packageUrl = "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/$publisher/vsextensions/$package/$version/vspackage"

    Write-Host "vscode: install $name"
    Write-Host "----------------------------------------"
    Invoke-RestMethod -Method Get -Uri $packageUrl -OutFile "$Env:Temp\$name.vsix" 
    code --install-extension "$Env:Temp\$name.vsix"
    Write-Host ""
}

Comments

comments

Nerdy Mishka