HTTPS GitHub URLs in package.json with node:12 Docker

Problem

You are getting an error like this:

The unauthenticated git protocol on port 9418 is no longer supported.

and/or you get this:

fatal: unable to access ... server certificate verification failed.

Solution - Part 1

For solving the first error you need to change the URLs in your npm package.json from "git://..." to "https://...".

Further information:

OK. So far so good.

Then you might get this error on "npm install":

fatal: unable to access 'https://github.com/some-user/awesome-library-project.git/': server certificate verification failed. CAfile: none CRLfile: none

Assuming that you use something like

FROM node:12.22.1-buster-slim

as the base image for your Docker image, the following is what you will need to do. Note that the node "buster" image is based on Debian Linux.

Solution - Part 2

Add the following to your Dockerfile (before the npm install step!):

RUN sudo apt-get install apt-transport-https ca-certificates -y
RUN sudo update-ca-certificates

"sudo" might not be necessary, in that case you can leave it away. There is even a shorter version in one line:

apt-get install apt-transport-https ca-certificates -y && update-ca-certificates

What it does is to update the list list of public root CA (certificate authorities) known to the system (but it's not a solution for private certificates!).

That should fix the error and make your Docker image building again!

I appreciate your feedback, e.g. by leaving a comment below or via Twitter - all further contact information can be found here.

Published: 2022-01-12 | Last update: 2022-01-12 | Tags: GitHub, Docker, npm, node.js, HTTPS, Git, certificate, package.json