Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am facing a certificate error while trying to install NPM packages on Windows. I am using Node v10.9.0

Tags:

node.js

npm

npm ERR! code ERR_TLS_CERT_ALTNAME_INVALID
npm ERR! errno ERR_TLS_CERT_ALTNAME_INVALID
npm ERR! request to https://registry.npmjs.org/http-server failed, reason: Hostname/IP does not match certificate's altnames: Host: registry.npmjs.org. is not in the cert's altnames: DNS:a.sni.fastly.net, DNS:a.sni.global-ssl.fastly.net

like image 417
tech4GT Avatar asked Sep 01 '18 11:09

tech4GT


People also ask

How do I fix npm installation errors?

If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).

How do I install npm files on Windows 10?

For Node. js projects, the easiest way to install npm packages is through the npm package installation window. To access this window, right-click the npm node in the project and select Install New npm Packages. In this window you can search for a package, specify options, and install.

Why I Cannot install npm?

On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

How do I force an npm package to install?

Run npm update -g npm. Execute this command by running the command prompt as Administrator npm install -g windows-build-tools. Run npm install inside the project folder where the package. json file is located, if it doesn't work run: npm install --force.


2 Answers

It seems that it's a real problem on the NPM servers. I see the same error when navigating to https://registry.npmjs.org/http-server in a browser. The server indeed doesn't have a valid certificate. Nothing Windows-specific.

NPM reports there's an issue with incorrect DNS information being cached, here: https://status.npmjs.org/incidents/v22ffls5cd6h

Until the cache clears up, they suggest doing the following:

  1. dig registry.npmjs.com @1.1.1.1
  2. Add the IP found to your /etc/hosts file.

Update: A bit unrelated, for ones using yarn: Yarn's mirror of the NPM registry seems to be affected by this problem too, so it seems that at the moment all we can do is wait until the issue resolves itself or the Yarn team applies a workaround on the server.

like image 175
Egor Kalinichev Avatar answered Oct 19 '22 09:10

Egor Kalinichev


The officially suggested solution with adding IPs found via the dig command into the hosts file somehow didn't work for me.

I found that there is a strict-ssl configuration option for npm.

Creating a .npmrc file in my project folder with strict-ssl = false solved the issue.

I find this solution safer and more isolated since editing the hosts file might not be possible for everyone and when it is, it will cause every request made from your computer to be routed to a specific IP address.

I plan to remove that file when this temporary issue is fixed.

like image 1
koraytaylan Avatar answered Oct 19 '22 09:10

koraytaylan