简体   繁体   中英

Get missing package golang.org/x/text/encoding/unicode import cycle

I'm trying to reproduce this go issue , but can't easily build their example:

$ cat main.go
package main
import ("fmt"; "golang.org/x/text/encoding/unicode")
func main() {
    res, err := unicode.UTF16(unicode.BigEndian, unicode.UseBOM).NewDecoder().String(" ")
    fmt.Println(res, err)
}
$ go mod init golang.org/x/text/encoding/unicode
go: creating new go.mod: module golang.org/x/text/encoding/unicode
go: to add module requirements and sums:
    go mod tidy
$ go mod tidy 1>/dev/null 2>/dev/null
$ go build main.go
package command-line-arguments
    imports golang.org/x/text/encoding/unicode
    imports golang.org/x/text/encoding/unicode: import cycle not allowed
go mod init golang.org/x/text/encoding/unicode

I suspect you should not initialise a project with a module name using the same name as your import.

Try:

go mod init test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM