Skip to content

"Can't load package" for package main declaration #226

Closed
@kkuchta

Description

@kkuchta

I'm trying to set up a hello world go project using modules and vscode. I'm using the go extension without the language server. I'm getting an error on the line package main when it seems like it should build cleanly.

My project consists of two files:

// src/go.mod
module whatever

go 1.14
// src/modtest.go
package main

import "fmt"

func main() {
	fmt.Println("hello, world")
}

VS Code shows an error on package main:

/Users/kevin/code/go/modtest>Finished running tool: /usr/local/bin/go build _/Users/kevin/code/go/modtest/src
can't load package: package _/Users/kevin/code/go/modtest/src: cannot find package "_/Users/kevin/code/go/modtest/src" in any of:
	/usr/local/Cellar/go/1.14.3/libexec/src/_/Users/kevin/code/go/modtest/src (from $GOROOT)
	/Users/kevin/code/go/src/_/Users/kevin/code/go/modtest/src (from $GOPATH

Screen Shot 2020-06-15 at 4 04 50 PM

This seems like vscode-go ought to build this cleanly. go build from within the src directory builds without error, and produces a functional binary. I apologize in advance if I'm just missing a minor configuration, or if I've misunderstood something about go project organization, but any help/advice would be very much appreciated!

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    go version go1.14.3 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
1.46.0
a5d1cc28bb5da32ec67e86cc50f84c67cc690321
x64
  • Check your installed extensions to get the version of the VS Code Go extension
    0.14.4
  • Run go env to get the go development environment details
go env                               
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kevin/Library/Caches/go-build"
GOENV="/Users/kevin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kevin/code/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h8/t6j1zhv57x97tdzs7rs0g2_h0000gn/T/go-build368033781=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

    "go.buildOnSave": "workspace",
    "go.formatTool": "goimports"

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeupstream-toolsIssues that are caused by problems in the tools that the extension depends on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions