I'm a bit new to Go, and I've been trying to use the SublimeLinter-contrib-gotype package to lint my files. It works well for the most part, but for some reason it throws an error if I try to import a Go package from GitHub. I've been trying to use the simple example from the Echo framework. When I run the code, it works fine but for some reason the linter is causing issues.
It throws an error saying:
could not import github.com/labstack/echo (can't find import: )
I've already run the go get github.com/labstack/echo command, but it doesn't seem to have helped.
I've attached a screenshot as well:
And here is a link to the code I was using.
I'd faced the same problem. Try running
launchctl setenv GOPATH $GOPATH
and restarting ST, this won't work after a reboot.
Source
If you use Go Sublime, the following should work better.
Sublime Text menu > Preferences > Package Settings > GoSublime > Settings - Default / User
"shell": ["/usr/bin/bash"],
"env": {"GOPATH": "/Users/username/gopath/"},
Related
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
I have latest IntelliJ Ultimate EAP and latest Gogland and the problem occurs on both under MacOS Sierra.
I'm trying to debug a go application by creating a debug profile for Go Application and the Run Kind is configured to Package, which contains the package name of the current project.
under Go tool arguments I have -ldflags="-linkmode internal" configured.
When I start a debug session while having some breakpoints, it would run but not stop at these breakpoints.
what am I missing?
thanks
update
ok I was able to reproduce the issue with the following project:
test1.go contains:
package main
const Numb uint64 = 5
test2.go contains:
package main
import "fmt"
func main() {
fmt.Println(Numb);
}
I Created a Go Application run/debug configuration with the following parameters:
Run kind: package
Package: github.com/kfirufk/test
Working Directory: /usr/local/Cellar/go/1.8.1/src/github.com/kfirufk/test/
when I choose a breakpoint on test2.go line 6 (the first and only line of code in the main function) and I start a debug session, I see the following output:
"/Users/ufk/Library/Application Support/IntelliJIdea2017.1/Go/lib/dlv/mac/dlv" --listen=localhost:53111 --headless=true exec /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo --
GOROOT=/usr/local/Cellar/go/1.8.1/libexec
GOPATH=/usr/local/opt/go
/usr/local/Cellar/go/1.8.1/libexec/bin/go build -o /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo -gcflags "-N -l" github.com/kfirufk/test
API server listening at: 127.0.0.1:53111
5
I get the program's output properly but Intellij did not stop in the required breakpoint.
the problem is reproduced on Intellij 2017.1.3 with Go Lang Plugin 0.171.1928 on MacOS Sierra 10.12.4.
update
trying to play with intellij's delve to try to understand better what's going on:
/Users/ufk/Library/Application\ Support/IntelliJIdea2017.1/intellij-go/lib/dlv/mac/dlv exec ./test
then I executed:
(dlv) step
and received:
Command failed: could not find FDE for PC 0x78bc000
did I fail to understand how to use delve or is something doesn't work properly here ?
update
yeap.. with continue the debugger works properly with both versions of delve (installed from homebrew and the intellij's version). but still intellij works the same, doesn't stop at breakpoints. i create a breakpoint at test2.go at the line when I print the variable.
any ideas ?
Ok.. I finally got it. I got mixed up with the GOROOT structure and GOPATH structure and I placed my project in GOROOT instead of GOPATH.
this is what I did to resolve the issue
I completely deleted go with brew uninstall --force go, then reinstalled go with the following environment variables:
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
then I placed my project at ~/golang/src/github.com/kfirufk/windy-server
and I was finally able to properly debug go applications.
thank you all for assisting me! :)
For my case (VSCode on Ubuntu 20.04), if the project is inside a symbolic link directory (or sub-dir of a symbolic dir), vscode will shows "unverified" breakpoints and
"Error on CreateBreakpoint: could not find file ..."
which leads to not stop on breakpoints.
cd \`readlink -f <project dir>\` && code .
will be ok.
For me, issue resolved adding:
export GOROOT="/usr/local/go"
to $HOME/.profile.
EDIT:
I'm using LiteIde X35.2, with Delve Debugger
Version: 1.1.0
Build: $Id: 1990ba12450cab9425a2ae62e6ab988725023d5c $
under:
DISTRIB=LinuxMint VERSION=18.3 CODENAME=sylvia
RELEASE=#41~16.04.1-Ubuntu SMP Wed Oct 10 20:16:04 UTC 2018
UBUNTU_CODENAME=xenial KERNEL=4.15.0-38-generic HDWPLATFORM=x86_64
DESKTOP_SESSION=XFCE WINDOWS_MANAGER=XFWM4
DESKTOP_COMPONENTS=kdevtmpfs gnome-keyring-d xfce4-session xfce4-panel
xfce4-volumed polkit-gnome-au xfce4-power-man xfce4-terminal
gnome-pty-helpe
GTK=libgtk-3-0:amd64 3.18.9-1ubuntu3.3 GStreamer=gst-launch-1.0
version 1.8.3 GStreamer 1.8.3
https://launchpad.net/distros/ubuntu/+source/gstreamer1.0
In my case, the process was already running at that port and didn't close. So I had to manually stop the process and run again from IntelliJ.
In my case (GoLand), the problem was with the flag -trimpath not being set in my debug configurations:
"Run", "Debug...", "Edit Configurations."
In the templates item, go to "Go Test" option and add the argument -trimpath in "Go tool arguments"
You can also set in your environment with:
go env -w GOFLAGS="-trimpath"
That also works for the "attach to process" debugging option.
You can see GoLand IDE Logs in the menu "Help", "Show Log Files". It will make your life easier.
Reference: https://youtrack.jetbrains.com/issue/GO-8277
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.
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.