19

This is my first time installing and using VSCode, and when I tried installing Prettier extension, it let me peek quickly at the extension page before closing it and displaying this notification (Screenshot attached):

Unable to open 'Extension: Prettier - Code formatter': An unknown error occurred. Please consult the log for more details..

VSCode screenshot: Notification at bottom right

It's doing this with all other extensions. Searched for a solution but found nothing applicable. Why is this happening and how to fix it?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Seif A.
  • 644
  • 2
  • 6
  • 17
  • You might use VSCode's developer console to learn more about the issue, https://stackoverflow.com/questions/30765782/the-use-of-developer-tools-in-vs-code However, I do suggest you open an issue with its vendor, https://github.com/prettier/prettier-vscode/issues who should have better knowledge on what might be wrong. – Lex Li Apr 13 '20 at 16:32
  • Have a look at https://stackoverflow.com/questions/61172590/extension-host-unexpectedly-teminated-vscode possibly related. – Mark Apr 13 '20 at 16:34

11 Answers11

36

It happens that, this is a problem with the Egyptian ISPs' default DNS servers, which are most probably blocking some of Microsoft servers.

The solution (in case you live in Egypt):

  1. clear DNS cache using ipconfig /flushdns command on Windows cmd (For Other OS).
  2. change the default DNS servers in your router settings to Google's 8.8.8.8 & 8.8.4.4 (or Cloudflare's 1.1.1.1 or any other DNS server you trust).
  3. restart VSCode and try installing extensions.

Hopefully, everything will work fine by now.

Check this Github issue for more insight.

Noha Salah
  • 493
  • 1
  • 7
  • 11
Seif A.
  • 644
  • 2
  • 6
  • 17
  • 1
    This is how to configure Windows 10 to set DNS: https://www.windowscentral.com/how-change-your-pcs-dns-settings-windows-10 – Ahmed Hammad Jun 21 '20 at 10:09
  • In my case, you don't need to proceed to step 2 onward. I flushed the DNS and it worked (Windows 10) – Bonifacius Sarumpaet Jan 11 '22 at 14:57
  • If you cannot/don't want to edit DNS settings, you can open code with the `--ignore-certificate-errors`, install the extensions you need, then restart without the flag. – Lewy Blue Aug 15 '22 at 05:35
7

It probably is because of the certificate check.

Below solution works for me in CentOS 7 (Linux).

Step 1. Change the file /usr/share/applications/code.desktop

Open the file /usr/share/applications/code.desktop, then modify the Exec value with adding --ignore-certificate-errors before %F:

Exec=/usr/share/code/code --unity-launch --ignore-certificate-errors %F

Save the file with typing sudo in the begining.

the file code.desktop

Step 2. Close all windows of vs code instances.

Step 3. Back to the terminal, use below command to open VS code:

code --ignore-certificate-errors

Step 4. Click extension button in the left side bar.

Click any extension like "Ruby" by Peng Lv, if the images in the Details page can be seen successfully, perhaps the issue is solved.

Step 5. Try to continue to install the extensions you need.

Just enjoy! May it be helpful for you.

Bravo Yeung
  • 8,654
  • 5
  • 38
  • 45
4

in ubuntu go to settings -> wifi -> click on gear icon -> IP4 -> dns input and put

8.8.8.8,8.8.4.4

and click apply, to DNS Resolver Cache open terminal and type:-

sudo systemd-resolve --flush-caches
sudo systemctl restart systemd-resolved

restart your device

4

For windows

    cd "C:\Users\<user>\Appdata\Local\Programs\Microsoft VS Code"
    code.exe --ignore-certificate-errors
linzwelch
  • 41
  • 2
  • This works for me except I can use `code.cmd` instead of `code.exe` and it's on the path so I don't need to change directory. – Lewy Blue Aug 15 '22 at 05:27
3

The solution

  1. clear DNS cache using command on Windows cmd: ipconfig /flushdns

  2. change the default DNS servers in your router settings to Google's:

    8.8.8.8 , 8.8.4.4 >> for IPv4

    2001:4860:4860::8888 , 2001:4860:4860::8844 >> for IPv6

    This link will guide you how to change the DNS server in windows and mac: https://www.ionos.com/digitalguide/server/configuration/how-to-change-dns-server/

  3. restart VSCode and try installing extensions.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
S.ahmed
  • 31
  • 1
2

If you're in a corporate network and it's locked down the one last resort is to manually download the VSIX from the website on a domain that will allow it and then copy over the VSIX and install it.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
1

I got this "XHR failed" error in Visual Studio Code.

So I changed my network settings to use Google Public DNS (instructions)

Finally following instructions (by mohamed-mokhtar) solved for me:

  • Go to : Control Panel\Network and Internet\Network Connections
  • Choose your connection network and ( right click on it then choose properties )
  • Select " Internet Protocol Version 4 (TCP/IPv4) and then click on properties in the bottom of this section
  • At General section click on " Use the following DNS Server address : "
  • Make " Preferred DNS server : 8.8.8.8 " (if you face a problem check this)
  • Make " Alternate DNS server : 8.8.4.4 "
  • Restart VS code
Mimina
  • 2,603
  • 2
  • 29
  • 21
1

referring to @Seif A. answer

The solution (in case you live in Egypt)

clear DNS cache using command on Windows cmd:

ipconfig /flushdns

change the default DNS servers in your router settings to Google's:

8.8.8.8 , 8.8.4.4  >> for IPv4
2001:4860:4860::8888 , 2001:4860:4860::8844  >> for IPv6

restart VSCode and try installing extensions.

1

I faced the same problem while adding new extension in vs code. I Recognized the problem within the ISP in Egypt, so I changed the DNS in My router to Google DNS Providers , and it works perfectly

A Hagrasi
  • 25
  • 5
0

Just install a VPN like betternet or any other VPN software and change the country to the USA or try other countries.

Abdelrahman Tareq
  • 1,874
  • 3
  • 17
  • 32
-1

In my case I was need to disable work VPN to download extension