VS Code – Golang "go module packages.Load error"

huangapple go评论86阅读模式
英文:

VS Code - Golang "go module packages.Load error"

问题

背景故事

我在我的新Windows 11专业版计算机上设置了一个新的虚拟机LMDE5时,遇到了这个错误以及其他很多错误。我大约有12年没有使用Windows了,而这些变化让Windows和LMDE5 Vbox上出现了无数错误。
我最后在vs code中遇到了这个问题。

错误信息

go module packages.Load error: err: exit status 2: stderr: go: no such tool "compile": go list

我的项目目录结构

.
├── docker-compose.yaml
├── project.code-workspace
├── go.mod
├── go.sum
├── main.go
└── sub_packages
    ├── backend
    │   ├── folder1
    │   ├── folder2
    ├── api
    │   ├── handlers
    │   └── requests
    ├── entities
    ├── services
    └── utils

settings.json 文件

{
    // ...
    "go.goroot": "/usr/local/go",
    "go.gopath": "/home/user_name/go",
    // ...
}
英文:

Backstory

I got this error amongst numerous others setting up a new virtual box LMDE5 on my new windows 11 pro computer. I haven't used windows in about 12 years, and the changes were crazy causing countless errors on Windows and LMDE5 Vbox.
My last issue was this in vs code.

Error

go module packages.Load error: err: exit status 2: stderr: go: no such tool "compile": go list

My project directory structure

.
├── docker-compose.yaml
├── project.code-workspace
├── go.mod
├── go.sum
├── main.go
└── sub_packages
    ├── backend
    │   ├── folder1
    │   ├── folder2
    ├── api
    │   ├── handlers
    │   └── requests
    ├── entities
    ├── services
    └── utils

settings.json file

{
    // ...
    "go.goroot": "/usr/local/go",
    "go.gopath": "/home/user_name/go",
    // ...
}

答案1

得分: 1

解决方案

将go工具目录的环境变量直接添加到VS Code的settings.json文件中,以便设置能够找到编译所在的文件夹.../linux_amd64的位置。

settings.json文件

{
    // ...
    "go.goroot": "/usr/local/go",
    "go.gopath": "/home/username/go",
    "go.alternateTools": {
        "GOTOOLDIR": "/usr/local/go/pkg/tool/linux_amd64"    
    },
    // ...
}
英文:

Solution

Add the go tool dir ENV variable directly to VS Code settings.json to the settings to pickup the location of the folder .../linux_amd64 where compile was located.

settings.json file

{
    // ...
    "go.goroot": "/usr/local/go",
    "go.gopath": "/home/username/go",
    "go.alternateTools": {
        "GOTOOLDIR": "/usr/local/go/pkg/tool/linux_amd64"    
    },
    // ...
}

huangapple
  • 本文由 发表于 2022年12月22日 08:37:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/74883120.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定