php editor Xigua may encounter an error message when using VS Code: "Cannot import the
I cannot import the URL package. Even if I install the packages on my system using "go get github..." and make sure they are present in the go.mod file, I see:
could not import <package> current file is not included in a workspace module
I remember just a few weeks ago I didn't even need to run "go work init" in every Golang project directory on my system. But now I'm asked to add these to the workspace. At that point, when I install any package from the terminal, I just import the installed package in my code and the code runs!
I am currently trying to create a project using understand "ebitengine", to do this I ran the following command
go mod init PROJECT (in the directory same as the code) go work init go get -u github.com/hajimehoshi/ebiten/v2 go mod init PROJECT (Again because the error was still being shown) go work init (Again because the error was still being shown)
Please help me understand what's wrong with my system and why I can't import packages correctly.
The output of running "go env" is:
GO111MODULE="auto" GOARCH="amd64" GOBIN="/home/user/go/bin" GOCACHE="/home/user/.cache/go-build" GOENV="/home/user/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/user/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/user/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.20.2" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/user/Desktop/learnings/go/14SwitchCase/go.mod" GOWORK="/home/user/Desktop/learnings/go/go.work" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1152057857=/tmp/go-build -gno-record-gcc-switches"
Similarly, my bashrc contains:
export GOPATH=$HOME/go export GOBIN=$GOPATH/bin export PATH=${PATH}:$GOBIN
Please help me understand where I am going wrong and why my VS Code no longer works properly.
The problem is the wrong GOPATH and GOROOT in my ~/.profile and ~/.bashrc files.
I replaced the existing GOPATH and GOROOT with the following lines and the problem was solved:
The above is the detailed content of 'Cannot import