简体   繁体   中英

VSCODE gopath different from GOPATH set in shell

I am encountering a very weird issue on visual studio code when i try to import packages.

import (
    "net/http"
    "github.com/gorilla/mux"
)

I get the error

cannot find package "github.com/gorilla/mux" in any of:
        /usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
        /user/chirrut/go/src/github.com/gorilla/mux (from $GOPATH)

however when i run go build from the terminal, I don't get any error. also note that the GOPATH is set to /home/chirrut/go instead of /user/chirrut/go I ran echo on terminal, and the vscode integrated terminal and both returns me the correct path.

$ echo $GOPATH
/home/chirrut/go

Somehow, somewhere VSCode is getting the GOPATH value as /user/chirrut/go instead. anyone have any idea where else is the GOPATH variable read from in VS Code?

This seems like a problem with the ms-vscode.go plugin, if I disable it, the problem go away. and if i enable it, it comes back. Strangely I tried uninstalling it completely, and then reinstall it again, and the problem goes away.

Note: No, I did not make any changes to GOPATH at all since i first setup golang.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM