Do you have a go.work file? If so, does it include the module in that 
directory?
(Compare https://go.dev/issue/51604.)

What do `go env GOMOD` and `go env GOWORK` report?

On Friday, April 1, 2022 at 10:05:57 AM UTC-4 vaastav...@gmail.com wrote:

> There is definitely source code in that folder. There is a main.go file as 
> well as 3 other packages. 
> So, go.mod should not be removing all the entries from the go.mod file.
>
> On Friday, 1 April 2022 at 15:43:30 UTC+2 Brian Candler wrote:
>
>> I just updated to 1.18 (from 1.17.6) - on macOS 12.3.1 - and indeed:
>> - with just go.mod, I get the warning and go.mod is cleaned up
>> - with go.mod plus main.go, I get no warning and go.mod is cleaned up
>>
>> This looks to me like a bug fix.  If there is no source code, then by 
>> definition go.mod should not have any dependent modules.
>>
>> On Friday, 1 April 2022 at 13:30:40 UTC+1 vaastav...@gmail.com wrote:
>>
>>> Ok, I just tested this. I only see this behaviour with go 1.18. I tried 
>>> using go mod tidy with go1.17 and it worked as expected.
>>>
>>> On Friday, 1 April 2022 at 14:15:14 UTC+2 vaastav...@gmail.com wrote:
>>>
>>>> I see this behaviour even in the presence of a main.go file in the same 
>>>> directory. This is why I am baffled as to why I am seeing this warning 
>>>> even 
>>>> if the source code is present.
>>>> It was working fine until I upgraded from go1.17 to go1.18
>>>>
>>>> On Friday, 1 April 2022 at 11:36:04 UTC+2 Brian Candler wrote:
>>>>
>>>>> Interesting.  If I put that go.mod file in an empty directory, then I 
>>>>> see the warning:
>>>>>
>>>>> $ go mod tidy
>>>>>
>>>>> go: warning: "all" matched no packages
>>>>> $ go mod tidy
>>>>>
>>>>> go: warning: "all" matched no packages
>>>>> > But when I run `go mod tidy`, it simply prints out the 
>>>>> aforementioned warning and the new go.mod file looks like this
>>>>>
>>>>> I see the same behaviour if I create a main.go file.  Then the warning 
>>>>> vanishes and the go.mod file is tidied:
>>>>>
>>>>> $ mv main.go.x main.go
>>>>> $ cat main.go
>>>>> package main
>>>>>
>>>>> func main() {
>>>>> }
>>>>> $ go mod tidy
>>>>> $ cat go.mod
>>>>> module module_name_obfuscated
>>>>>
>>>>> go 1.17
>>>>> $ 
>>>>>
>>>>> This of course is expected behaviour: it's the job of go mod tidy to 
>>>>> update the go.mod file so that it matches the source code in the module. 
>>>>> See "go help mod tidy":
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *"Tidy makes sure go.mod matches the source code in the module.It adds 
>>>>> any missing modules necessary to build the current module'spackages and 
>>>>> dependencies, and it removes unused modules thatdon't provide any 
>>>>> relevant 
>>>>> packages."*
>>>>>
>>>>> So I presume the warning you see is only when go mod tidy can't find 
>>>>> any source code in the current directory.
>>>>>
>>>>> On Thursday, 31 March 2022 at 20:18:52 UTC+1 vaastav...@gmail.com 
>>>>> wrote:
>>>>>
>>>>>> Here are the contents of the go.mod file
>>>>>>
>>>>>> ```
>>>>>> module module_name_obfuscated
>>>>>>
>>>>>> go 1.18
>>>>>>
>>>>>> require (
>>>>>>     github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
>>>>>>     github.com/go-redis/redis/v8 v8.11.4
>>>>>>     github.com/go-sql-driver/mysql v1.6.0
>>>>>>     github.com/otiai10/copy v1.7.0
>>>>>>     github.com/rabbitmq/amqp091-go v1.3.0
>>>>>>     github.com/tracingplane/tracingplane-go 
>>>>>> v0.0.0-20171025152126-8c4e6f79b148
>>>>>>     gitlab.mpi-sws.org/cld/tracing/tracing-framework-go 
>>>>>> v0.0.0-20211206181151-6edc754a9f2a
>>>>>>     go.mongodb.org/mongo-driver v1.7.4
>>>>>>     go.opentelemetry.io/otel/exporters/jaeger v1.2.0
>>>>>>     go.opentelemetry.io/otel/exporters/zipkin v1.6.0
>>>>>>     go.opentelemetry.io/otel/sdk v1.6.0
>>>>>>     go.opentelemetry.io/otel/trace v1.6.0
>>>>>>     golang.org/x/mod v0.5.1
>>>>>> )
>>>>>>
>>>>>> require (
>>>>>>     github.com/cespare/xxhash/v2 v2.1.2 // indirect
>>>>>>     github.com/dgryski/go-rendezvous 
>>>>>> v0.0.0-20200823014737-9f7001d12a5f // indirect
>>>>>>     github.com/go-logr/logr v1.2.3 // indirect
>>>>>>     github.com/go-logr/stdr v1.2.2 // indirect
>>>>>>     github.com/go-stack/stack v1.8.0 // indirect
>>>>>>     github.com/golang/protobuf v1.5.2 // indirect
>>>>>>     github.com/golang/snappy v0.0.4 // indirect
>>>>>>     github.com/klauspost/compress v1.13.6 // indirect
>>>>>>     github.com/openzipkin/zipkin-go v0.4.0 // indirect
>>>>>>     github.com/pkg/errors v0.9.1 // indirect
>>>>>>     github.com/xdg-go/pbkdf2 v1.0.0 // indirect
>>>>>>     github.com/xdg-go/scram v1.0.2 // indirect
>>>>>>     github.com/xdg-go/stringprep v1.0.2 // indirect
>>>>>>     github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // 
>>>>>> indirect
>>>>>>     go.opentelemetry.io/otel v1.6.0 // indirect
>>>>>>     golang.org/x/crypto v0.0.0-20210920023735-84f357641f63 // 
>>>>>> indirect
>>>>>>     golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
>>>>>>     golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
>>>>>>     golang.org/x/text v0.3.7 // indirect
>>>>>>     golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // 
>>>>>> indirect
>>>>>>     google.golang.org/protobuf v1.27.1 // indirect
>>>>>> )
>>>>>> ```
>>>>>>
>>>>>> But when I run `go mod tidy`, it simply prints out the aforementioned 
>>>>>> warning and the new go.mod file looks like this:
>>>>>>
>>>>>> ```
>>>>>> module module_name_obfuscated
>>>>>>
>>>>>> go 1.18
>>>>>> ```
>>>>>> On Thursday, 31 March 2022 at 18:30:13 UTC+2 Brian Candler wrote:
>>>>>>
>>>>>>> Can you show the contents of the go.mod file in the directory where 
>>>>>>> you run "go mod tidy"?
>>>>>>>
>>>>>>> > I get this error when I run `go list all` as well.
>>>>>>>
>>>>>>> Try "go list" rather than "go list all" (because in that context, 
>>>>>>> "all" is interpreted as the name of a package)
>>>>>>>
>>>>>>> On Thursday, 31 March 2022 at 16:12:24 UTC+1 vaastav...@gmail.com 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi all,
>>>>>>>> I am encountering this problem where when I run `go mod tidy`, it 
>>>>>>>> simply returns `go: warning: "all" matched no packages`. I get this 
>>>>>>>> error 
>>>>>>>> when I run `go list all` as well. 
>>>>>>>> I was hoping someone could help me as to why this is happening 
>>>>>>>> since I haven't been able to find an explanation for this.
>>>>>>>>
>>>>>>>> Kind Regards
>>>>>>>> Vaastav
>>>>>>>>
>>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c1f8b5a3-6516-4c63-be23-c0e2f79c0624n%40googlegroups.com.

Reply via email to