go: x/tools/gopls: duplicate module in workspace with experimentalWorkspaceModule

Issue

I use multi-module workspace (kinda monorepo). I’m getting below error from gopls for all the modules in pkg -

found module "github.com/Shopify/sarama" twice in the workspace

I found I have different versions of sarama. But I believe that is not causing this. because, The error is pointing all the modules. I have attached the screenshot with this for more details.

What version of Go are you using (go version)?

$ go version
go version go1.15.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/sram/Library/Caches/go-build"
GOENV="/Users/sram/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/sram/ram/project/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/sram/ram/project/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sn/pw7xq23n2vj_wnq16lkgdrxh0000gn/T/go-build150007759=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

gopls settings

    "gopls": {
         "ui.documentation.hoverKind": "SynopsisDocumentation",
         "build.directoryFilters": ["-/Users/sram/ram/project/node/","-node_modules"],
         "build.experimentalWorkspaceModule": true,          
      }

What did you expect to see?

No errors or warnings.

What did you see instead?

Error that says

found module "github.com/Shopify/sarama" twice in the workspace

Below is the screenshot of error:

Screen Shot 2021-03-23 at 11 53 45 AM Screen Shot 2021-03-23 at 9 13 24 AM

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 36 (18 by maintainers)

Most upvoted comments

As a datapoint I disabled experimentalWorkspaceModule because of this

In my case we have a few submodules | /src/ | | go.mod | | /deps/ | | | /goproject2/ | | | /goproject3/ | | | | /deps/ | | | | | /goproject2/

In this case goproject2 shows up twice because it is our submodule, and a submodule of a dependency we have.

Admittedly it’s a strange project structure but we chose it because we can craft very efficient makefiles that let us modify dependencies quickly.

I wish the following statement were true: “if go build can build knows that to do with your file, then gopls can resolve the same dependencies go build will”