在构建 Go 项目时出现了“package io/fs 不在 GOROOT 中”的错误。

huangapple go评论87阅读模式
英文:

package io/fs is not in GOROOT while building the go project

问题

我在Go方面没有太多经验,但我被指派执行一个Go项目 在构建 Go 项目时出现了“package io/fs 不在 GOROOT 中”的错误。

所以我需要构建这个Go项目,然后执行它。

当我构建Go项目时出现以下错误。似乎缺少一些依赖项(package和io/fs)。

transform/transform.go:13:2: package embed is not in GOROOT (/usr/local/Cellar/go/1.15.8/libexec/src/embed)
pkg/util/fs.go:4:2: package io/fs is not in GOROOT (/usr/local/Cellar/go/1.15.8/libexec/src/io/fs)

我的Go环境如下:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/<XXXXX>/Library/Caches/go-build"
GOENV="/Users/<XXXXX>/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/<XXXXX>/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/<XXXXX>/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.8/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.8/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/<location to the project>/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5h/9qptf0sx3c12226jnqt75q8r0000gp/T/go-build648466970=/tmp/go-build -gno-record-gcc-switches -fno-common"

请注意,这只是一个翻译,我无法为你解决构建错误。你可能需要检查你的依赖项和环境设置,确保所有的包和模块都正确安装和配置。

英文:

I don't have much experience in go but I have been tasked to execute a go project 在构建 Go 项目时出现了“package io/fs 不在 GOROOT 中”的错误。

So i need to build the go project and then execute it

Below is the error when i build the go project. Seems to be some dependency(package and io/fs) is missing

transform/transform.go:13:2: package embed is not in GOROOT (/usr/local/Cellar/go/1.15.8/libexec/src/embed)
pkg/util/fs.go:4:2: package io/fs is not in GOROOT (/usr/local/Cellar/go/1.15.8/libexec/src/io/fs)

my go env

GO111MODULE=&quot;on&quot;
GOARCH=&quot;amd64&quot;
GOBIN=&quot;&quot;
GOCACHE=&quot;/Users/&lt;XXXXX&gt;/Library/Caches/go-build&quot;
GOENV=&quot;/Users/&lt;XXXXX&gt;/Library/Application Support/go/env&quot;
GOEXE=&quot;&quot;
GOFLAGS=&quot;&quot;
GOHOSTARCH=&quot;amd64&quot;
GOHOSTOS=&quot;darwin&quot;
GOINSECURE=&quot;&quot;
GOMODCACHE=&quot;/Users/&lt;XXXXX&gt;/go/pkg/mod&quot;
GONOPROXY=&quot;&quot;
GONOSUMDB=&quot;&quot;
GOOS=&quot;darwin&quot;
GOPATH=&quot;/Users/&lt;XXXXX&gt;/go&quot;
GOPRIVATE=&quot;&quot;
GOPROXY=&quot;https://proxy.golang.org,direct&quot;
GOROOT=&quot;/usr/local/Cellar/go/1.15.8/libexec&quot;
GOSUMDB=&quot;sum.golang.org&quot;
GOTMPDIR=&quot;&quot;
GOTOOLDIR=&quot;/usr/local/Cellar/go/1.15.8/libexec/pkg/tool/darwin_amd64&quot;
GCCGO=&quot;gccgo&quot;
AR=&quot;ar&quot;
CC=&quot;clang&quot;
CXX=&quot;clang++&quot;
CGO_ENABLED=&quot;1&quot;
GOMOD=&quot;/Users/&lt;location to the project&gt;/go.mod&quot;
CGO_CFLAGS=&quot;-g -O2&quot;
CGO_CPPFLAGS=&quot;&quot;
CGO_CXXFLAGS=&quot;-g -O2&quot;
CGO_FFLAGS=&quot;-g -O2&quot;
CGO_LDFLAGS=&quot;-g -O2&quot;
PKG_CONFIG=&quot;pkg-config&quot;
GOGCCFLAGS=&quot;-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5h/9qptf0sx3c12226jnqt75q8r0000gp/T/go-build648466970=/tmp/go-build -gno-record-gcc-switches -fno-common&quot;

答案1

得分: 34

这个软件包需要 go v1.16,请升级您的go版本或使用适当的Docker构建器。

英文:

This package requires go v1.16, please upgrade your go version or use the appropriate docker builder.

huangapple
  • 本文由 发表于 2021年8月12日 13:36:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/68752103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定