Getting ERR_INVALID_PROTOCOL error when running npm commands

I’m experiencing an annoying problem whenever I try to run npm. This is the error that keeps popping up:

npm error code ERR_INVALID_PROTOCOL

npm error Protocol "https:" not supported. Expected "http:"

npm error A complete log of this run can be found in: /home/.npm/_logs/2025-06-10T05_50_28_066Z-debug-0.log

It happens every time I try to start a new project or add new packages. I’m unsure if there’s a problem with my npm setup or if others have faced this issue. Can anyone share their thoughts on why npm doesn’t accept the https protocol when it should be compatible? Any tips on resolving this would be greatly appreciated.

I encountered this exact error about six months ago and it drove me nuts for hours. The issue was actually with my proxy settings interfering with npm’s protocol handling. Check if you have any corporate proxy or VPN running that might be forcing protocol redirects. You can verify this by running npm config list and looking for any proxy-related configurations. If you see http-proxy or https-proxy entries, try clearing them with npm config delete proxy and npm config delete https-proxy. Also worth checking your .npmrc file in your home directory for any hardcoded proxy settings that might be causing the protocol mismatch. Fixed it completely for me once I cleared those out.

This error typically occurs when there’s a corrupted npm cache or configuration file causing protocol confusion. I faced something similar last year when my npm installation got messed up after a system update. What worked for me was clearing the npm cache completely using npm cache clean --force and then checking if there were any corrupted .npmrc files in both my project directory and home directory. Sometimes npm reads conflicting protocol settings from multiple configuration sources. You might also want to try reinstalling npm entirely using npm install -g npm@latest after clearing the cache. The protocol error usually indicates npm is getting mixed signals about whether to use http or https, so cleaning out all cached data and config conflicts should resolve it.

maybe ur npm is pointing to an old registry. try npm config get registry and see if it’s the right one. if not, use npm config set registry https://registry.npmjs.org/ to fix it. gl!