'VScode show me the error after I install the proxy in vscode
gopls requires a module at the root of your workspace. You can work with multiple modules by opening each one as a workspace folder. Improvements to this workflow will be coming soon (https://github.com/golang/go/issues/32394), and you can learn more here: https://github.com/golang/go/issues/36899.
Solution 1:[1]
You probably have more than one go module in your workspace. If that is the case, you can change the go extension settings, in order to allow gopls to look for multiple modules in the workspace. Just add the following to your settings.json
:
"gopls": {
"experimentalWorkspaceModule": true,
}
You can read more about gopls
configuration in the docs: https://github.com/golang/tools/blob/master/gopls/doc/settings.md
Solution 2:[2]
To solve this, follow below steps :
step 1 : Open Vscode, and then go to settings.
step 2 : In the search bar , type gopls
step 3 : Just below that you will find settings.json, click on that
step 4 : Paste the below code their "gopls": { "experimentalWorkspaceModule": true, }
step 5 : Save it and restart the Vscode, You are good to go now.
Solution 3:[3]
I had this error because I had not created my modules inside a src
directory. So I had:
$GOPATH
-> bin
-> pkg
-> github.com
-> Module
-> go.mod
and that needed to be:
$GOPATH
-> bin
-> pkg
-> src
-> github.com
-> Module
-> go.mod
Solution 4:[4]
Go 1.18+
From Go 1.18 onwards there is native support for multi-module workspaces.
This is done by having a go.work
file present in your parent directory.
For a directory structure such as:
$ tree /my/parent/dir
/my/parent/dir
??? project-one
? ??? go.mod
? ??? project-one.go
? ??? project-one_test.go
??? project-two
??? go.mod
??? project-two.go
??? project-two_test.go
Create and populate the file by executing go work
:
cd /my/parent/dir
go work init
go work use project-one
go work use project-two
This will add a go.work
file in your parent directory that contains a list of directories you marked for usage:
go 1.18
use (
./hello-world
./integers
)
Solution 5:[5]
The setting has changed, now you need to use:
"gopls": {
"build.experimentalWorkspaceModule": true,
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Stefano Mozart |
Solution 2 | Abhishek Nishad |
Solution 3 | Liam |
Solution 4 | |
Solution 5 | Skatox |