Intellij shows all modules in go.mod as undefined

已完成

I create a new project from existing sources.  I set the GOROOT for the project.  GOPATH is set correctly.  I've run go get and go mod tidy on the project.  Running go build from the command line on one of the main.go files in the cmd/ directory builds a binary.  (There are multiple main.go files in this project.)

Intellij shows every module in go.mod as an Unresolved Dependency.  In .go files Intellij shows all imports that are not part of the Go installation as unresolved directories.  This is on Windows.

Why is Intellij showing these errors when this project is structured properly and builds properly from the command line?

 

评论操作 固定链接

Is Go modules integration enabled via File | Settings | Languages & Frameworks | Go | Go Modules? What options are available if you press Alt+Enter on unresolved imports inside Go files?

1
评论操作 固定链接

Enabling go modules integration solved this.  Modules integration should be enabled when you create a new project from source code that has a go.mod file in it.

0
评论操作 固定链接

Thanks for the update. Go modules integration will be enabled automatically since the 2022.1 update.

0
评论操作 固定链接

I downloaded GoLand 2022.1.2 (Build #GO-221.5787.30, built on May 31, 2022) today and the Go modules integration was not enabled automatically.

0
评论操作 固定链接

Spencer Tuft, can you reproduce it if you delete .idea directory in the project root? Most likely, .idea directory exists before you've opened the project in the IDE and it inherits previous settings.

0
评论操作 固定链接

Daniil Maslov, you're correct. New projects appear to have the Go modules integration setting enabled by default. Thanks!

1

请先登录再写评论。