"Cannot resolve symbol" in package import

已完成

I am just getting started with Go, with a new private module that has a dependency on the

github.com/timescale/promscale

go get github.com/timescale/promscale@0.6.2 + go mod tidy worked fine from the command line, and generated the go.mod below.

In the IDE however imported packages from that module are flagged with a "Cannot find symbol xxx" error

import (
"fmt"
"github.com/timescale/promscale/pkg/version"
)

If I open go.mod in Goland then the line below

require github.com/timescale/promscale v0.0.0-20211012192453-b648bcd6ee27

is flagged with a "Missing dependency" error.

Using Sync dependencies (either in the source file, or in go.mod) gives me a "finishied successfully" message, but the errors are still there.

What am I missing?

go.mod:

module acme.com/prommeter

go 1.17

require github.com/timescale/promscale v0.0.0-20211012192453-b648bcd6ee27

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
...
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
...
)
0
正式评论

I've reproduced your steps and got a bit different results:

  • Create a new Go modules project, open Terminal (View | Tool Windows | Terminal)
  • Execute go get github.com/timescale/promscale@0.6.2

After these steps, you should get go list -m -json -mod=mod all execution by the IDE and it fails with the following error:

go list -m: k8s.io/client-go@v12.0.0+incompatible: invalid version: +incompatible suffix not allowed: module contains a go.mod file, so semantic import versioning is required

It means that semantic import versioning is not followed in k8s.io/client-go dependency. You can get the same error from the terminal by executing go list -m -json -mod=mod all.

However, there is a workaround. You can use replace directive in your go.mod file and specify the semver version in the right way:

module go-1-17-project

go 1.17

require github.com/timescale/promscale v0.0.0-20211124134648-bf2760feabf9

require github.com/blang/semver/v4 v4.0.0 // indirect

replace k8s.io/client-go => k8s.io/client-go v12.0.0+incompatible

After that, execute Sync Go Module again and go list -m -json -mod=mod all returns your dependencies and resolve them inside the IDE.

As you can see, the same approach is applied inside go.mod file for timescale/promscale project and prometheus/prometheus dependency.

If you did not get invalid version: +incompatible suffix not allowed error, please let me know and we'll investigate it together.

I hope it helps.

Thanks, that works.

I also got dependency resolution working by add this to the Git env variables:

GOFLAGS=-e

 

2

All my problems got fixed by adding the env var “GOFLAGS=-e” aswell, thank you very much Franck

0

请先登录再写评论。