1

I have deployed my Golang sls on Vercel, now I'm trying to add one of my private repo as a dependency, but during deployment I'm seeing follwing error

Error: Command failed: go mod tidy
go: github.com/user/[email protected]: reading github.com/user/repo/go.mod at revision v0.0.1: unknown revision v0.0.1

the revision/tag exists and I could set up and test everything from local. But I don't see in any vercel docs how I can configure Vercel to access these private repos. Vercel has read access to my GitHub private repo(dependency).

1 Answer 1

1

Go uses git under the covers to pull dependencies. You need to grant git access to your private repos.

On build system's like TravisCI, a typical way to grant such access is through an access token and a .netrc file, filling in the secret token via Travis stored environment variables:

# .netrc
## generate token with https://help.github.com/articles/creating-an-oauth-token-for-command-line-use
machine github.com login <token>

EDIT:

From the Vercel Docs:

To install private packages with go get, define GIT_CREDENTIALS as a build environment variable in vercel.json. ... With GitHub, you will need to create a personal token with permission to access your private repository.

{
  "build": {
    "env": {
      "GIT_CREDENTIALS": "https://username:[email protected]"
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, but my code is hosted on vercel, Vercel pulls repo from my GitHub, and run go mod tidy on it. so the only way to make .netrc file available to Vercel is to commit it to my repo, which is not a good idea.
@mahendra I've update the answer to include the relevant technique to add a github access token to your build process

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.