cannot resolve directory of all the import

已完成

So the 「Cannot resolve directory」error just pop up today (used to work normally before..)

not sure how to fix it, I've tried "go clean --modcache" and "go mod download" but still couldn't fix

below is my go env:

```

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/chris/Library/Caches/go-build"
GOENV="/Users/chris/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/chris/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="/Users/chris/Workspace/device-sdk-go/go.mod"
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/nr/rc6cpjnn0753bj5sgz776tgw0000gn/T/go-build247994700=/tmp/go-build -gno-record-gcc-switches -fno-common"
```

And I have the GOROOT and GOPATH set correctly in the goland preferences, I also Enabled Go Modules (vgo) integration and set 

Vgo Executable: Project SDK

Proxy: direct

 

Let me know if any further information is needed and thanks for the help in advance.

2

I tried everything here and the only thing that helped me was removing the .idea directory.

2

I have the same issue, I am using go mods. I am using the workaround mentioned by "Appto

 ( remove your `.idea` folder & open your project  ).

Is there a fix for this issue yet?

 

Env

GoLand 2021.2
Build #GO-212.4746.93, built on July 26, 2021

 

0

Thilak T, please, collect the IDE logs via Help | Collect Logs and Diagnostic Data and upload them to https://uploads.jetbrains.com/, provide its ID. Are you using GOPATH or Go Modules? Thank you.

0

Hello Daniil Maslov, here is the ID 2021_08_16_XYwN8iCN6nTCqMuG.

Yes, I am using GOMOD

0

Thanks. Unfortunately, I haven't found any suspicious in your logs. Are you using Git to version control the content inside the .idea folder? If so, could you please upload old and new .idea directories? I'll compare them to understand the underlying reasons.

0

I had this issue, restarting my IDE solved it. 

1

Its a problem with .idea folder. Delete it at file explorer and reopen IDE again

0

SV, do you have a backup with the previous .idea directory? If so, could you please upload two versions to https://uploads.jetbrains.com/ and provide its ID? Thank you.

0

This is happening to me 6 out of 10 times using Idea 2021.3.2 Ultimate.
Reverting to the previous version (2021.2.4) fixes the issue for me.

I tried to clear the cache and restart, delete the .idea folder, re-initialise the project, but it would just work temporarily and the issue would come back again when re-opening the project a few more times.

I am using Go Modules, MacOS 11.6.3.

Hope this helps.

0

luigitni, have you renamed a project root directory or project name recently?

0

Daniil no I did not rename any project or root folder - just tried to remove the .idea folder or invalidate caches.

The problem started to occur when I started to use the 2021.3.2 (build IU-213.6777.52) version.
Opening the same project with 2021.2.4 (build IU-212.5712.43) has never caused the issue so far.

This is what happens in more detail:

  1. The progress bars in the bottom right that appear when opening a new project run to completion very fast
  2. imports in .go files and in the go.mod file are coloured red
  3. The IDE does not recognise namespaces in code: suggestions do not work and the editor shows errors when using import packages methods/structs
  4. CMD+Enter does not show the option to sync dependencies neither in the .go files or in go.mod
  5. Running the build configuration from the IDE successfully builds and starts the executable

Hope this helps

0

luigitni, thanks for the follow-up. Are project directories displayed in yellow color when it happened?

0

Daniil Thanks to you for looking into this.
No, project folders are grey (like "Extensions" in the picture above).

The project root has a blue square on the bottom right side of the icon.

 

0

luigitni, thanks. Please collect the IDE logs (step #3 in https://youtrack.jetbrains.com/issue/GO-11961#focus=Comments-27-5654986.0-0) right after it happens again and upload them to https://uploads.jetbrains.com/, then provide its ID.

0

Fix is trivial. Just add your Go path to module path lol. Absolutely infuriating amount of hours lost until I found this 

2

Hi y'all, 
I had the same problem with GoLand 2021.3.2. I tried every solution mentioned earlier but it did not work for me. As Sidpat said I deleted the .idea folder and re-open the project from the project folder and it is fixed. This is so disturbing, can you please fix this bug?  

1

Saozdamar, could you please collect the IDE logs (Help | Collect Logs and Diagnostic Data) and upload them to https://uploads.jetbrains.com/ when it happens again?

0

Hi Daniil I just had the exact same issue occur and deleting the .idea folder and re-opening GoLand resulted in dependencies correctly being picked up. Have uploaded logs. Hopefully it helps in debugging. Upload id: 2022_06_20_SQAeyqv86RKVejTrQ3MDdq (file: goland-logs-20220620-10273814297933141429579528.zip)

0

Martin Madsen, thank you. Will investigate.

1

This issue is still happening on Build #GO-213.6777.51

My workaround is:

  1. run `go mod vendor`
  2. wait for Goland to finish indexing
  3. delete the vendor directory
  4. wait for Goland to finish indexing

This is quicker than the invalidate cache and restart workaround 

0

Roblovelock, could you please update GoLand to the latest available version to see if it helps?

0

go to your go.mod file and cut all the dependencies out of the file so your requires is empty and save it. Paste them back in and save. Worked for me

0
Make sure Go Modules integration is enabled in settings (Preferences / Settings | Go | Go Modules), and GOPATH indexing is disabled (Preferences / Settings | Go | GOPATH | Index entire GOPATH).


We did it already.

All dependencies are synchronized. To do it, go to any .go file, hover over the import and press Alt(Option)+Enter, then select "Sync Dependencies of ...".


The thing is when this occurred, there is no option to sync dependencies:



GoLand 2022.1.3

0

Quan Tong Anh, please update GoLand to 2022.2.2, collect IDE logs (Help | Collect Logs and Diagnostic Data), upload them to https://uploads.jetbrains.com/ and provide its ID.

0

I had the same problem. I deleted .idea folder and this solved the problem. The issue persisted after I updated to the latest version #GO-222.4345.24

1

IDE doesn't know `$GOPATH/pkg/mod/<package>` instead it only knows `$GOPATH/src`. `$GOPATH/src` is no longer works when we make `go get github.com/bla/bla`

0

dtherhtun.cw, please make sure that Go modules integration is enabled in Preferences | Go | Go modules. If it doesn't help – upload the IDE logs (Help | Collect Logs and Diagnostic Data) to https://uploads.jetbrains.com/ and provide the ID.

0

 Go to `Project structure` in setting and add your root folder fixed the issue

0

The answer from Appto solved it for me

0

I had the same problem with GoLand 2023.1.4
I removed the project and cloned it again. It solved the problem.
Dear Goland developers, this bug is present since 2020

0

请先登录再写评论。