0

I am trying to open my project in VSCode but I get the following error

could not import github.com/gorilla/mux (current file is not included in a workspace module)compilerBrokenImport

The above error goes for every third party and internal packages created in my project

My folder structure is the following:

.
├── Makefile
├── README.md
├── api
│   ├── CHANGELOG.adoc
│   ├── Makefile
│   ├── README.md
│   ├── cmd
│   ├── cover.out
│   ├── dev
│   ├── docs
│   ├── env.sample
│   ├── go.mod
│   ├── go.sum
│   ├── groupsyncd
│   ├── iamd
│   ├── idmd
│   ├── internal
│   ├── mocks
│   ├── sonar-project.properties
│   ├── userlockd
│   └── vulnerability-suppression.xml
├── api-qa
│   ├── README.md
│   ├── pom.xml
│   ├── src
│   └── target
├── bin
│   └── entrypoint.sh
├── compose
│   ├── iam.yml
│   ├── idm.yml
│   ├── keycloak.yml
│   ├── localstack.yml
│   ├── mongodb.yml
│   └── mysql.yml
├── dev
│   ├── bundle.tar.gz
│   ├── context.tar.gz
│   ├── example.rego
│   ├── export-realm
│   ├── get-access-token
│   ├── idm-permissions.gz
│   ├── init
│   ├── jsonserver
│   ├── localstack
│   ├── mongodb
│   ├── nginx.conf
│   ├── setup-protocol-mapper
│   └── test-realm.json
├── docker-compose.yml
├── dockerfiles
│   ├── iam-api
│   ├── idm-api
│   ├── idm-energon
│   ├── idm-groupsync
│   ├── idm-userlock
│   ├── jsonserver
│   └── mongodb
├── env.sample
├── go.work
└── protos
    ├── commons
    └── energon.proto

It's a single modules project. my work file placed on the root folder has the following contents

go 1.20

use ./api

My go env from root directory

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/avlachopoulos/Library/Caches/go-build"
GOENV="/Users/avlachopoulos/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/avlachopoulos/.gvm/pkgsets/go1.20/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/avlachopoulos/.gvm/pkgsets/go1.20/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/avlachopoulos/.gvm/gos/go1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/avlachopoulos/.gvm/gos/go1.20/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/avlachopoulos/go.mod"
GOWORK="/Users/avlachopoulos/development/ocp-iam/idm/go.work"
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sw/lsrfw_3d537_w16x9cw3yynj7kg71v/T/go-build2156756382=/tmp/go-build -gno-record-gcc-switches -fno-common"

and my go env from "module" directory

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/avlachopoulos/Library/Caches/go-build"
GOENV="/Users/avlachopoulos/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/avlachopoulos/.gvm/pkgsets/go1.20/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/avlachopoulos/.gvm/pkgsets/go1.20/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/avlachopoulos/.gvm/gos/go1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/avlachopoulos/.gvm/gos/go1.20/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/avlachopoulos/development/ocp-iam/idm/api/go.mod"
GOWORK="/Users/avlachopoulos/development/ocp-iam/idm/go.work"
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sw/lsrfw_3d537_w16x9cw3yynj7kg71v/T/go-build903840586=/tmp/go-build -gno-record-gcc-switches -fno-common"

Really frustrating setting it up. Before the language server it just worked!Any help setting it up will be appreciated.

Apostolos
  • 7,763
  • 17
  • 80
  • 150
  • Did you try running `go get github.com/gorilla/mux` or updating the VScode tools - `ctrl` + `shift` + `p` -> `Go: install/Update Tools` – emir.hamidovic Jun 15 '23 at 09:37
  • Yes for the second one. No for the first one, but the same error exists for my internal packages as well. So I cannot do go get "path/to/internal/package". It works if I disable the language server – Apostolos Jun 15 '23 at 09:44
  • I tried to emulate your project layouts but everything is working for me. I'm using the language server and it can successfully lint my workspace, etc. Can you provide me with more details? or maybe jump in a chat and try to debug it. – ossan Jun 15 '23 at 12:21
  • The issue was resolved by changing my root folder to `api` which contains the go.mod. This is not a solution though since root folder contains other necessary files like docker files etc. @ossan we can check it if you like just not right now. When would you be available? Though I cannot show code or screen, this is proprietary stuff. – Apostolos Jun 16 '23 at 13:54
  • With "root folder" do you mean the folder you open up with VSCode? If you want, I'm available to dig into it. Just let me know when it's suitable for you! – ossan Jun 16 '23 at 14:33
  • Yes with root folder I mean just that. It is one level higher than the folder containing the go.mod. – Apostolos Jun 17 '23 at 16:23
  • Hello @ossan can you please print a tree of your directory? is it exactly like the one that I posted? – Apostolos Jun 19 '23 at 09:28
  • Hey @Apostolos, let's DM me so I can share an image of my working directory or change it accordingly to match your need. – ossan Jun 19 '23 at 10:00
  • Sorry I didn't have time to do it, due to working hours. I still have the same issue. I create a go.work file with go work init on the parent folder of the go module (folder with go.mod) run go work sync but my vscode project isn't recognizing the dependencies and asking me to run go mod get. It looks really buggy to me – Apostolos Aug 08 '23 at 09:15
  • Also from the documentation this isn't working either: If you are working with a single module, you can open the module root (the directory containing the go.mod file), a subdirectory within the module, or a parent directory containing the module. Note: If you open a parent directory containing a module, it must only contain that single module. Otherwise, you are working with multiple modules. Mine is a single module and opening the parent directory nor does it recognise it neither does the memory keep low (high CPU high memory consumption of go process) – Apostolos Aug 08 '23 at 09:18
  • Please consider this as fixed. The reason was that there was an orphaned go.mod folder on the parent directory of my project dir (homedir) which caused the issue – Apostolos Aug 08 '23 at 11:21

0 Answers0