Go.mod has not need package


(Qingyunha) #1

The modules name is zorro. After build, it has a not need package golang.rog/x/text

$ go mod tidy 

$ go mod graph | grep text
zorro golang.org/x/text@v0.3.2
github.com/kr/pretty@v0.2.0 github.com/kr/text@v0.1.0
golang.org/x/text@v0.3.2 golang.org/x/tools@v0.0.0-20180917221912-90fa682c2a6e
github.com/kr/text@v0.1.0 github.com/kr/pty@v1.1.1

$ go mod why golang.org/x/text
# golang.org/x/text
(main module does not need package golang.org/x/text)

(Lutz Horn) #2

Maybe there is a transitive dependency on golang.org/x/text. We can’t tell without seeing all dependencies.


(Qingyunha) #3

This is the go.mod

module zorro

go 1.13

require (
	github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
	github.com/bitly/go-simplejson v0.5.0
	github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
	github.com/fsnotify/fsnotify v1.4.7
	github.com/go-ole/go-ole v1.2.4 // indirect
	github.com/hpcloud/tail v1.0.1-0.20180514194441-a1dbeea552b7
	github.com/kr/pretty v0.2.0 // indirect
	github.com/robfig/cron v1.2.0
	github.com/shirou/gopsutil v2.19.12+incompatible
	github.com/sirupsen/logrus v1.4.2
	github.com/urfave/cli v1.22.2
	github.com/xgfone/go-tools v5.2.0+incompatible
	golang.org/x/text v0.3.2
	gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
	gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)


(Lutz Horn) #5

If I read the help (go help mod why) correctly, the output you get is what should be expected. If both your code and any dependency don’t depend on a module, go mod why will print (main module does not need package golang.org/x/text). This looks correct to me.

I don’t quite understand your question.


(Qingyunha) #6

But why the golang.rog/x/text appear in go.mod?
As go help mod tidy says

it removes unused modules that don’t provide any relevant packages.


(Lutz Horn) #7

Does golang.org/x/text still appear in go.mod after go mod tidy? Note that go mod why does not tell you if a module is listed in go.mod but what would be the reason to list it there.


(Qingyunha) #8

Yes, golang.org/x/text still appear in go.mod after go mod tidy. This is what I confused.


(Qingyunha) #9

If I remove golang.org/x/text manually, go build still success.
But After I run go mod tidy, the golang.org/x/text appear in go.mod again.


(Lutz Horn) #10

Strange indeed.


(Qingyunha) #11

Strange . go mod graph say golang.org/x/text required by zorro, but go mod why say don’t need it.


(Qingyunha) #12

I see. golang.org/x/text is a module not a package., so the correct command is go mod why -m golang.org/x/text. :joy: