Visual Studio Code "Error while fetching extensions. XHR failed"

Viewed 70574

This problem started a few weeks ago, when I started using NordVPN on my laptop. When I try to search for an extension and even when trying to download through the marketplace I get this error: enter image description here

EDIT: Just noticed another thing that might indicate to what's causing the issue. When I open VSCode and go to developer tools I get this error messege (before even doing anything):

"(node:19368) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.(Use Code --trace-deprecation ... to show where the warning was created)"

The only partial solution I found so far was to manually download and install extensions.

I've checked similar question here and in other places online, but I didn't find a way to fix this. So far I've tried:

  1. Flushing my DNS cache and setting it to google's DNS server.
  2. Disabling the VPN on my laptop and restarting VS Code.
  3. Clearing the Extension search results.
  4. Disabling all the extensions currently running.

I'm using a laptop running Windows 10. Any other possible solutions I haven't tried?

15 Answers

I had the same problem, I did the following steps to solve it

All you need to do is enter to the JSON settings file from VSC

1. Press F1
2. Type User Settings
3. Search for Proxy
4. In proxy section, look for the title `Http: Proxy Authorization`
5. Click on 'Edit in settings.json'
6. Delete all brackets containing proxy data
7. Save JSON file

After that, just restart VSC You can also find the JSON in %appdata%/Code/User/settings.json

For me , 'XHR failed' error appears when the proxy settings between your PC system and vs code are conflict.

1.Check PC system proxy settings.

2.Open cmd or terminal, type

echo %http_proxy%, if any output, make sure it fits your pc proxy setting. Because if the proxy on vs code not being set, will be inherited from the http_proxy and https_proxy environment variables.

3.If none, open vs code settings.json , add "http.proxy":"http://proxyname:port" that fits your pc proxy setting ,without a trailing slash.

Try download extensions again.Hope this helps. ^^

so i find this

  1. press f1
  2. search user setting
  3. click enter
  4. search on user setting " proxy "
  5. click enter
  6. look for "use the proxy support for extensions."
  7. change override to on

maybe this can help you.

In my case, the solution was to remove HTTPS_PROXY (Could be HTTP_PROXY) environment variable set at terminal initialization. I removed the line which sets the environment variable for proxy, restarted the OS and the error disappeared.

Apart from ~/.bashrc for bash or any other sh-compatible shell, environment variable could be in

  • /etc/environment: specifically meant for environment variables
  • /etc/env.d/*: environment variables, split in multiple files
  • /etc/profile: all types of initialization scripts
  • /etc/profile.d/*: initialization scripts
  • /etc/bashrc, /etc/bash.bashrc: meant for functions and aliases
  • ~/.bash_profile: initialization for login (bash-)shells
  • ~/.bashrc: initialization for all interactive (bash-)shells
  • ~/.profile: used for all shells
  • ~/.cshrc, ~/.zshrc, ~/.tcshrc: similar for non-bash shells

Credit to this post. https://unix.stackexchange.com/a/249922

December 10,2021.
I'm using vscode with ubuntu 20.04.
I came across the XHR errors from yesterday and could not install any extensions.
Googled a lot but nothing works.
Eventually I downloaded and installed the newest version of VSCode(deb version) and everything is fine now. (I don't know why but maybe you can give it a try! Good Luck!)

I got the same error with the .deb version from the visualstudio.com page.

Have you tried opening the Developer Tools (F1, Developer Tools). Which error is returned? I had ERR_CERT_AUTHORITY_INVALID. The --ignore-certificate-errors command-line flag is a workaround for me (as indicated here https://code.visualstudio.com/docs/setup/network).

I'm using windows 11 and I was having the same issue. My laptop has a Killer wifi board and it comes with a option to "enable game fast". It was checked to start automatically with a game. I just unchecked it and this error stopped to show up.

I hope your problem will be easy as mine to solve. Try maybe your firewall.

As far as I am aware the XHR error has several possible causes. The easiest fix which should be attempted prior to more complicated methods is restarting VS Code.

I have seen this error a couple of times and have been able to resolve it this way, for me it was not related to proxy settings, whereas for other users it might be. A possible relevant scenario is running a VS Code instance without restart or update over prolongued periods of time, such as days or even weeks.

For me i had to disable this option from Visual Studio Code.

For me i had to disable this option from Visual Studio Code.

I faced this problem in 7-2022, and it's gone without even restart vscode. The reason was poor internet connection. If this is ur situation check the quality of your internet connection and just click refresh button, then extensions appear after a moment!

In my Windows machine deleting http_proxy User Environment Variable helped me.

I don't use a proxy, and I do use NextDNS so I didn't want to change my DNS settings.

As a workaround, you can open code with --ignore-certificate-errors flag, install any extensions, then restart without the flag.

On windows:

code --ignore-certificate-errors

In my case http_proxy system environment variable was set in Windows 10. After deleting that VS code started loading extensions.

I have faced the same issue. And I delete the .vscode-server directory in server. Reconnect my server successful.

I have had the same issue on Debian 10 and fixed it by downgrading VSCode to an older version 1.33.1.

Related