App Engine: node.js dependency with git+https URL

Viewed 135

If we deploy a node.js 12 project to App Engine (standard environment) and it has a dependency in package.json that looks like this:

"some-lib": "git+https://github.com/a/b.git",

Then this will lead to a deployment error when we execute gcloud app deploy. This is from the App Engine logs:

Step #6 - "builder": npm ERR! Error while executing:
Step #6 - "builder": npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/a/b.git
Step #6 - "builder": npm ERR! 
Step #6 - "builder": npm ERR! Host key verification failed.
Step #6 - "builder": npm ERR! fatal: Could not read from remote repository.

So even though the dependency is provided as a HTTPS URL, it will try to fetch it with SSH and this doesn't seem to work on App Engine.

It works if I go to package-lock.json and manually change the version string to start with https, but that's not really a viable solution, because it will be overwritten again.

Any ideas how it can be accomplished to provide a dependency with a GitHub URL (SSH or HTTPS) to App Engine?

2 Answers

Check first your git configuration in the deployment environment (Google App Engine, in your Google Cloud Console), assuming Git 2.26 or more:

git config --global --show-origin --show-scope-l
git config --system --show-origin --show-scope -l
# if you are in a local repository:
git config --local --show-origin --show-scope -l

Look for any configuration like url."ssh://git@github.com".insteadOf "git+https://github.com"

Such a rule would rewrite the URL, explaining why your initial dependency shows up as an SSH URL.

As we can see in this issue the problem relies in NPM that caused to convert any git+https reference into git+ssh.

From what I understood, the issue has been patched but is not available on NPM 6, that is the version used in the nodejs12 and nodejs14 enviroment of GAE.

What I suggest is to use nodejs16 as runtime of your App Engine application

Related