Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types: cannot locate transient dependency saved via Go modules #27556

dradtke opened this issue Sep 7, 2018 · 4 comments

go/types: cannot locate transient dependency saved via Go modules #27556

dradtke opened this issue Sep 7, 2018 · 4 comments


Copy link

dradtke commented Sep 7, 2018

What version of Go are you using (go version)?

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build423725469=/tmp/go-build -gno-record-gcc-switches"

What did you do?

1. Ensure a clean slate.

Steps 2 and 3 set up a fresh Go development environment on a new Linux server for maximum reproducibility (I spun up a new CentOS server on Vultr). Alternatively, delete ${GOPATH}/pkg and ${GOPATH}/src/ if they exist.

2. Install the latest Go:

# run as root
$ cd /usr/local
$ wget
$ tar xvf go1.11.linux-amd64.tar.gz

# also need to install Git on a fresh server
$ yum install git

3. Create a new user and set them up for Go development:

# run as root
$ useradd --create-home damien
$ su - damien

# now run as damien
$ mkdir go
$ export GOPATH=~/go
$ export PATH=/usr/local/go/bin:${PATH}

4. Create a new project outside of GOPATH.

I created a new workspace directory, and inside that added app/app.go:

// ~/workspace/app/app.go
package app

import (

func UnicodeVersion() string {
	return norm.Version

I then ran the following to enable Go modules and install its dependency:

$ go mod init app
$ go get

The app folder now contains 3 files: app.go, go.mod, and go.sum, all with the expected contents. Of note is the fact that go.mod does not contain a direct reference to, but instead its parent package:

module app

require v0.3.0 // indirect

Running go build ensures that everything works, and indeed we can see the dependency stored at ~/go/pkg/mod/\@v0.3.0/.

5. Use go/types to type-check it.

I wrote a small program that uses the go/types package to typecheck a program:, which should be saved in ~/workspace.

What did you expect to see?

Given that the program builds fine, I would expect to see no errors when type-checking it.

What did you see instead?

The program fails with the following error:

2018/09/07 14:43:05 app/app.go:4:2: could not import (type-checking package "" failed (/home/damien/go/pkg/mod/ could not import (cannot find package "" in any of:
	/usr/local/go/src/ (from $GOROOT)
	/home/damien/go/src/ (from $GOPATH))))
exit status 1

In addition, using importer.Default() instead results in an even simpler error:

2018/09/07 14:47:04 app/app.go:4:2: could not import (can't find import: "")
exit status 1
Copy link

myitcv commented Sep 7, 2018

With Go modules, you need to use (often shorted to just go/packages) to type check your code. go/packages uses the Go tool in order to be module-aware. As you can see from the definition of go/packages.Package, it has a field of type go/types.Package.

There is more discussion about go/packages happening in!forum/golang-tools and in #tools on Gophers Slack.

I can't really say this is "working as intended", but I'm going to close the issue in any case. Please feel free to join us in golang-tools in case you have any queries about the use of go/packages.

@myitcv myitcv closed this as completed Sep 7, 2018
Copy link

dradtke commented Sep 7, 2018

@myitcv How stable would you say go/packages is? I see an all-caps note at the top of the docs page saying that it's not yet ready for widespread use.

Copy link

myitcv commented Sep 7, 2018

That warning is more relevant to pre the Go 1.11 release (cc @matloob - any update required here?).

go/packages is being used as the basis for the rewrite of many (if not all) go tools: #24661. It is build system agnostic, understands modules, will be more powerful etc. It should be used for all tools requiring anything from module/package file lists, to syntax trees, type information and much more.

Hence that warning should probably be read as "please start using and road testing go/packages, on the understanding we might make minor API changes".

@ianthehat's team is responsible for go/packages so I'll let him add anything I might have missed.

Copy link

We will probably be changing the warning soon, at this point its more along the lines of: the API is fairly stable, we will be trying hard not to break it without a really good reason, and we would prefer if you are using it you come talk to us in golang-tools in case we do need to break it so we can let you know. We are not yet ready to promise it's fully stable, we need to be able to make changes when we find a tool that really needs something it cannot support.

@golang golang locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

4 participants