美文网首页
GoLand报错:package XXX is not in G

GoLand报错:package XXX is not in G

作者: 87d6dc4b11a7 | 来源:发表于2022-01-12 11:58 被阅读0次

使用GoLand运行写好的代码报错,报错信息:

package gowiki is not in GOROOT (D:\Program Files\Go\src\gowiki)

Compilation finished with exit code 1

通过命令行进入项目目录执行go buildgo run就可以成功。
说明:

GOROOT=D:\Program Files\Go
GOPATH=D:\go

项目路径:D:\go\src\gowiki
解决:
方法一:
进入项目目录执行go mod,执行完会在该目录生成go.mod文件。

go mod init example/hello

方法二:设置GO111MODULE=off

go env -w GO111MODULE=off

Go Modules

模块是Go管理依赖的方式。

go mod命令

Go mod provides access to operations on modules.

Note that support for modules is built into all the go commands,
not just 'go mod'. For example, day-to-day adding, removing, upgrading,
and downgrading of dependencies should be done using 'go get'.
See 'go help modules' for an overview of module functionality.

Usage:

        go mod <command> [arguments]

The commands are:

        download    download modules to local cache
        edit        edit go.mod from tools or scripts
        graph       print module requirement graph
        init        initialize new module in current directory
        tidy        add missing and remove unused modules
        vendor      make vendored copy of dependencies
        verify      verify dependencies have expected content
        why         explain why packages or modules are needed

Use "go help mod <command>" for more information about a command.

相关文章

网友评论

      本文标题:GoLand报错:package XXX is not in G

      本文链接:https://www.haomeiwen.com/subject/cbnjcrtx.html