2 Simple Solutions to Fix Missed Dependencies of a Go Module

No answer in StackOverflow (yet), when you relocate a middle-large go project, you will encounter this issue.

Background: I am moving the built environment of our AI Cervical Cancer project from Virtual Box to Vmware Fusion, the project is using:

  • Github (public/private) for source code
  • Ubuntu 16.04 (guest operating system)
  • Mac OS (Big Sur)
  • VMware Fusion (v12.04, free version)
  • Swag (v1.7.0, for generating Restful API)
  • Vue.js (GUI, front end)
  • Golang (v1.13.3, back end)

Problem

The github.com/qiniu/x revision 7.0.8 doe NOT exist anymore. Most advises are suggesting to modify the version in the go.mod, here is our go.mod:

The go.mod has NOT been built yet. If I try to build by either “go build” or “go run”, or even “go get -u” to add more dependencies, it will be showing the same error.

So it won’t work by modifying the go.mod. Now what we do to fix it?

go.mod is generated by `$ go mod init {your project name}` even before the main.go existed. It will be modified by `go build -o {your project name} main.go`

Solution 1: using a newer revision

  • First, let's list all the available versions the github.com/qiniu/x has:
$ go list -m -versions github.com/qiniu/x                                         
github.com/qiniu/x v1.7.0 v1.7.3 v1.7.4 v1.7.5 v1.7.6 v1.7.7 v1.7.8 v1.8.0 v1.8.1 v1.8.2 v1.8.4 v1.8.5 v1.10.0 v1.10.1 v1.10.2
v1.10.3 v1.10.4 v1.10.5 v1.10.6 v1.10.7 v1.10.8 v1.10.9 v1.11.0 v1.11.2 v1.11.3 v1.11.5

you can see there is no v7.0.8

  • Get a specific version:
$ go get github.com/qiniu/x@v1.8.1
  • Replace any versions with specified version(v1.8.1) of a package (github.com/qiniu/x), in go.mod
replace (
github.com/qiniu/x => github.com/qiniu/x v1.8.1
)

Solution 2: copy the missed package from another cached system

If you have a workable system that can build successfully, you can do the following steps :

  1. Go to your workable system:
$cd $GOPATH/pkg/mod/cache

2. Find your missed package and do the gzip, in my case:

$gzip -czvf my_missed_package ./my_missed_package

3. copy “my_missed_package” to my new system, put it into the same directory: $GOPATH/pkg/cache

4. unzip it:

$cd $GOPATH/pkg/mod/cache
$unzip my_missed_package.gz

Medical AI, computer vision, interest:self-supervised learning+annotation, imbalanced datasets, AI in embedded devices. Personal AI project: cervic.hopto.org