So I installed VSCODE on my windows machine as my main golang IDE and I guess my overall lack of go knowledge is making me experience this seemingly unsolvable error:
I installed delve and wanted to use it as my debugger in vscode-go. I did everything as mentioned in the readme on https://github.com/Microsoft/vscode-go , yet for some reason when I run dlv debug I get error "can't load package: package internal: no buildable Go source files in c:\go\src\internal exit status 1". I couldn't find anything related to this folder on the internet, but I have never myself entered the path to src/internal in any of the config files. So this is making me really confused, since I thought if it was a common folder someone should have atleast gotten the same error once.
It occurs both in the vscode and in command prompt, also if dlv test is run. I also know it is not the issue with my folder structure/env variables since it complains about my package files missing too if I remove them in addition to also giving the same c:\go\src\internal error. It seems as if there is a setting somewhere to check that folder for source files too, but I can't find the setting and the dlv debug crashes after giving me the error.
Got same issue with latest delve and vscode:
can't load package: package internal: no buildable Go source files in
C:\Coding\Go\src\internal
and 'go build' working without any errors
Have to fallback to previous version of delve to get it working. It seems delve broke something or just need to update some things. Seems it enough just to replace dlv.exe in %GOPATH%\bin folder. I'm not sharing my version because it exe, but you can find it or build from sources
I solved my problem that looks like same problem by changing launch.json file.
// before
"program": "${workspaceRoot}
// after changing
"program": "${workspaceRoot}/src/github.com/myproje/hello",
I had the same problem. When i check, {fileDirName} points my .vscode folder. So i've just given my path manuelly and it works.
I've replaced this
"program": "${fileDirname}"
with this
"program": "c:/Go/src/MyGoProject"
same problem (vscode/linux/go1.8)
The Solution:
change in launch.json >
"program": "${fileDirname}"
If Go is installed correctly, this error message is saying you are trying to import an external package called "internal"
Compile an empty program with no imports to see if the issue persists eg.
package main
func main() {
}
You should not see any errors here. If you do then that is most likely an indication Go is not installed properly.
Related
Sorry if this is a silly question - just getting started with Go.
I have installed 'go 1.13' (due to this being the version currently supported by Cloud Functions) and the latest version for the VSCode Go extension. This is all in Windows.
I then followed the Go Getting Started Guide. All seems to be working fine - I can run the application and VSCode does not report any syntax errors etc.
Now VSCode just gives me a nagging error message whenever I open a .go or .mod file:
Unable to execute 'go list'' command, run 'go mod tidy' to know more
Running the go mod tidy command does not result in any output. The other tools, such as gopls where installed successfully by VSCode. Any idea what could cause this and how it can be fixed?
This error is caused by the 'Dependency Analysis' extension (redhat.fabric8-analytics). Disabling this extension will result in the error not being shown anymore.
This error is also listed in the FAQ for the Dependency Analysis extension:
FAQ Item 3: Failed to run golist command.
Suggestion: Resolve the error thrown by go mod tidy and go list for the project and try again.
Maybe this will work for someone else but it didn't work for me (only disabling the extension did). In any case, I've raised an issue at the extensions GitHub rep fabric8-analytics/fabric8-analytics-vscode-extension to see if there is another fix but disabling the extension.
I just install the latest version(1.16.3) and work for me.
This question appears to have been asked in Go updates to go.mod needed, disabled by -mod=readonly : packages.Load error but was not answered there, so re-posting it. Running Go 1.15.7, I'm trying to load a Go project with a go.mod but VS Code is showing a notification with the following error:
Error loading workspace: err: exit status 1: stderr: go: updates to go.mod needed, disabled by -mod=readonly : packages.Load error
It seems that a read-only mode is enabled, but I'm not sure how to disable this. I've tried simply increasing the file permissions on go.mod,
chmod a+w go.mod
but to no avail. Any idea how to fix this error and allow the Go extension to load?
This error appears to have resolved itself by just running
go mod tidy
manually. I'm still curious what caused this, though, as the extension might still not be fully working.
You can easily fix this by just adding to your settings.json a gopls build parameter allowing imports from out-of-scope modules.
Something along the lines of:
{
"gopls": {
"build.allowModfileModifications": true
}
}
For reference: https://github.com/golang/vscode-go/blob/master/docs/settings.md#buildallowmodfilemodifications
And a little more context:
In Go 1.16, the Go command will no longer modify user's go.mod and go.sum files automatically (https://tip.golang.org/doc/go1.16#tools). In order to match this behavior, gopls now also uses -mod=readonly when running the go command. Any errors reported by the go command will be presented with a suggested fix to make the necessary fixes to your go.mod or go.sum files. As a consequence, your workspace may be in a partially broken state while you have errors in your go.mod or go.sum file. golang/go#42266 will mitigate this, but it will likely not be resolved until February.
Not recommended: If you must opt out of this behavior, you can set the allowModfileModifications configuration to true.
Check the PROBLEMS section or the corresponding go.mod file. When such problems are detected, gopls provides quickfix and hints on how to address them there. If not, that's a bug.
I have project in Go. After I set up debugger and launch in Visual Code,
it failed with this error output. I am using go 1.13.4 in /usr/local/go
/usr/lib/go-1.10/src/crypto/tls/cipher_suites.go:18:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/chacha20poly1305 expects import "golang.org/x/crypto/chacha20poly1305"
/usr/lib/go-1.10/src/crypto/x509/x509.go:36:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/cryptobyte expects import "golang.org/x/crypto/cryptobyte"
/usr/lib/go-1.10/src/crypto/x509/x509.go:37:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/cryptobyte/asn1 expects import "golang.org/x/crypto/cryptobyte/asn1"
/usr/lib/go-1.10/src/crypto/tls/key_agreement.go:20:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/curve25519 expects import "golang.org/x/crypto/curve25519"
/usr/lib/go-1.10/src/net/http/h2_bundle.go:48:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/net/idna expects import "golang_org/x/text/internal/export/idna"
/usr/lib/go-1.10/src/net/http/transport.go:32:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/net/proxy expects import "golang.org/x/net/proxy"
This seems to happen when you have a newer version of Go available on your PATH.
I worked around it by uninstalling Go 1.13 from /usr/local, but there may be better ways to handle it if you need to have multiple versions installed.
I had the VSCode Go debugger working with go.goroot set to a Go 1.11 install I was using for my project. I installed Go 1.13 into /usr/local to test out a feature and then ran into this same error.
If you have a different Go version on the PATH it seems like it's using that compiler, but compiling against the standard library sources in your other Go version. In later Go versions this directory has been renamed back to vendor/golang.org, and it doesn't recognize the golang_org hack that was used previously:
https://github.com/golang/go/commit/4d00937cecdea85b6f1eb894a6d28a53f5f2ff8a#diff-44c7c5a1dcc556d22e115d30ec0f11c9
I'm not certain if this is a general problem with Delve, or an issue with how the VSCode Go extension calls it, but the simplest solution in my situation was to uninstall Go 1.13 and the debugger started working again.
Your problem has nothing to do with the debugger. If you would have searched for the key parts of these errors, you would have discovered that the error is due to the fact since v1.4 Go supports so-called "canonical imports".
Most probably some packages in your project were vendored using their "hosting" URLs (such as github.com/what/ever) instead of their canonical URLs suggested by the error message.
The proper solution is to revendor the affecting packages the correct way.
If you merely want the code to build "as is" no matter what, you could edit the code of these packages to remove "canonical import comments" from them.
My vscode does not detect errors in golang.
Example:
package somepackage
import "fmt"
func f(name string) string {
name = 1
return name
}
This should throw a type error, but it does not. I never get any errors.
My settings.json contains
"go.gopath": "some/path",
"go.vetOnSave": "package",
"go.lintOnSave": "package",
"go.testOnSave": true,
"go.buildOnSave": "package",
"go.coverOnSave": true
I was able to run go: install/update Tools. All tools are installed successfully.
I am also able to run debug a .go file in vscode.
As #pwaterz pointed out, the solution to my problem was to add "go.goroot: /some/other/path".
The reason that vscode was not able to detect errors was, that there are different go versions on my computer. Adding the goroot and running go: install/update Tools solved the problem.
---- Edit: Multiple go versions ----
Had multiple conflicting go versions on my Mac, pulled in via brew. Fixed the problem with a reinstall.
Uninstall go and also run brew uninstall go
Reinstall go
Set environment variables in your .bash_profile or similar. Compare here.
Apply the changes to your profile by running e.g. source .bash_profile
Restart VSCode
In settings.json set "go.goroot": "/usr/local/go"
Run go: Toggle workspace trust space to make sure changes to settings.json are applied (you have to trust your workspace for that)
go: Install/update tools and select all
---- Edit: Incorrect root folder ----
Make sure that you open the root folder of your project and not a sub-folder of your project. That may cause in invalid import paths otherwise
---- Edit: Broken language server ----
Try to run go: restart language server
You may see Error loading workspace
run go mod tidy and try again
When i am trying to install golint (or gin, for example) i get "unrecognized import path error".
I know that there are many same questions, but main answer is to check environment variables.
There is screenshot of my environment variables, my folders and console with error.
I tried to install go both with .msi installer and just by copying files and setting env var manually. I got the same results.
There is a go get issue currently discussed
my go tools were out of date, but go get could not update them because they switched form mercurial to git at some point. Deleting the whole golang.org/x/tools directory in my GOPATH and reinstalling fixed the issue.
Make sure you have the latest go, and try with a fresh empty GOPATH folder, to see if the issue persists.