英文:
VS Code showing me "Error loading workspace: found module "main.go" twice in the workspace"
问题
我正在使用主要的GO扩展。
我经常使用VS Code,现在我正在学习GO语言。
每次打开VS Code时,我都会遇到以下问题:
加载工作区时出错:在工作区中找到了两个"main.go"模块。
尽管代码运行时输出正确,但我不知道如何解决这个问题。
有人可以帮我解决这个错误吗?
英文:
I am using the primary GO extension.
I use VS code a lot, now I'm learning GO lang.
And when I open VS Code every time I'm getting this:
Error loading workspace: found module "main.go" twice in the workspace.
While running the code it's giving the right output.
I don't know how to fix this.
Anybody, help me with this error.
答案1
得分: 4
最好只在VSCode中打开一个带有自己go.mod
项目的文件夹。
在1.18版本中,支持多个go.mod
/项目的工作区。
go
命令现在支持“工作区”模式。如果在工作目录或父目录中找到
go.work
文件,或者使用-workfile
标志指定了一个文件,它将将go命令置于工作区模式。
在工作区模式下,将使用go.work
文件来确定用作模块解析根的一组主模块,而不是使用通常找到的go.mod
文件来指定单个主模块。
正如Varun Kumar在“如何使VScode Go在多模块存储库中工作”中所描述的那样,这曾经起作用:
如果您想在单个工作区中使用所有嵌套模块,有一个可选的模块功能,允许在不为每个模块创建工作区文件夹的情况下使用多个模块。在您的设置中设置此项 -
"build.experimentalWorkspaceModule": true
但是,从2022年9月起,此功能已被弃用。
请参阅gopls
文档“设置您的工作区”以了解更多信息。
英文:
It would be better to open in VSCode only one folder with its own go.mod
project.
A workspace with multiple go.mod
/project should be supported with 1.18
> The go
command now supports a "Workspace" mode.
>
> If a go.work
file is found in the working directory or a parent directory, or one is specified using the -workfile
flag, it will put the go command into workspace mode.
In workspace mode, the go.work
file will be used to determine the set of main modules used as the roots for module resolution, instead of using the normally-found go.mod
file to specify the single main module.
As described in "How to make VScode Go work in a Multi-Module Repo" from Varun Kumar, this used to work:
> If you want to work with all the nested modules in a single workspace, there is an opt-in module feature that allows to work with multiple modules without creating workspace folders for each module. Set this in your settings -
>
> "build.experimentalWorkspaceModule": true
But as per september 2022 is deprecated.
See more at gopls
documentation "Setting up your workspace".
答案2
得分: 0
请检查以下内容:
- 确保你在VSCode中只打开了一个项目。
- 确认你的GOPATH设置正确。
- 确保同一个项目中没有两个go.mod文件。
- 确认你已经安装了推荐的Golang工具(VSCode插件)。
英文:
Check that:
- you have only one project is open in vscode
- your GOPATH is set correctly
- you don't have 2 go.mod in the same project
- you installed the recommended tools(vscode) for golang
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论