google / wire

Compile-time Dependency Injection for Go
Apache License 2.0
13.13k stars 623 forks source link

go: -mod may only be set to readonly or vendor when in workspace mode, but it is set to "mod" #405

Closed yangyile1990 closed 8 months ago

yangyile1990 commented 8 months ago

my problem is:

go: -mod may only be set to readonly or vendor when in workspace mode, but it is set to "mod" Remove the -mod flag to use the default readonly value, or set GOWORK=off to disable workspace mode.

what is wrong?

//go:generate go run -mod=mod github.com/google/wire/cmd/wire

can not work.

edit the code to this:

//go:generate go run github.com/google/wire/cmd/wire

can work.

while after work the code is replace back to:

//go:generate go run -mod=mod github.com/google/wire/cmd/wire

then can not work.

I have to edit the code again.

may be there is some thing wrong here:

    buf.WriteString("// Code generated by Wire. DO NOT EDIT.\n\n")
    buf.WriteString("//go:generate go run -mod=mod github.com/google/wire/cmd/wire" + tags + "\n")
    buf.WriteString("//+build !wireinject\n\n")
    buf.WriteString("package ")
    buf.WriteString(g.pkg.Name)
    buf.WriteString("\n\n")

it always generete code:

//go:generate go run -mod=mod github.com/google/wire/cmd/wire

or may be there is some other wrong.

but I don't know how to fix it.

CoreFloDev commented 8 months ago

that's a duplicate of https://github.com/google/wire/issues/403

yangyile1990 commented 8 months ago

that's a duplicate of #403

OK let me close this issue. and wait for you solve that problem.