gpt4 book ai didi

go - 如何解决 Golang 在 golang.org/x/tools/go 中找不到包?

转载 作者:行者123 更新时间:2023-12-01 22:23:33 36 4
gpt4 key购买 nike

这个问题只是在构建之间随机出现,现在甚至我们的生产 repo,几个月都没有改变,在构建时也会出现这个问题。我已经坚持了一段时间。它不会发生在我们的本地机器上,只有在使用 dockerfile 时才会发生。

Step 30/73 : RUN go get -d ./...
---> Running in ca969a5fc165
[91msrc/golang.org/x/text/cmd/gotext/main.go:31:2: cannot find package "golang.org/x/tools/go/buildutil" in any of:
/usr/local/go/src/golang.org/x/tools/go/buildutil (from $GOROOT)
/app/src/golang.org/x/tools/go/buildutil (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:23:2: cannot find package "golang.org/x/tools/go/callgraph" in any of:
/usr/local/go/src/golang.org/x/tools/go/callgraph (from $GOROOT)
/app/src/golang.org/x/tools/go/callgraph (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:24:2: cannot find package "golang.org/x/tools/go/callgraph/cha" in any of:
/usr/local/go/src/golang.org/x/tools/go/callgraph/cha (from $GOROOT)
/app/src/golang.org/x/tools/go/callgraph/cha (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:25:2: cannot find package "golang.org/x/tools/go/loader" in any of:
/usr/local/go/src/golang.org/x/tools/go/loader (from $GOROOT)
/app/src/golang.org/x/tools/go/loader (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:26:2: cannot find package "golang.org/x/tools/go/ssa" in any of:
/usr/local/go/src/golang.org/x/tools/go/ssa (from $GOROOT)
/app/src/golang.org/x/tools/go/ssa (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:27:2: cannot find package "golang.org/x/tools/go/ssa/ssautil" in any of:
/usr/local/go/src/golang.org/x/tools/go/ssa/ssautil (from $GOROOT)
/app/src/golang.org/x/tools/go/ssa/ssautil (from $GOPATH)
[0mThe command '/bin/sh -c go get -d ./...' returned a non-zero code: 1

我已经将所有这些依赖项(减去第一个)跟踪到 golang.org/x/text/message/pipeline/extract.go 中的一个文件。它们都被列为进口商品。下面是我们dockerfile的相关部分
RUN yum update -y
RUN yum install -y git-core
RUN yum install -y wget
RUN yum install -y gcc-c++ make
RUN yum install -y libaio
RUN yum install -y openssl-devel


# Install Go
RUN wget --no-check-certificate https://dl.google.com/go/go1.12.2.linux-amd64.tar.gz
RUN tar -xzf go1.12.2.linux-amd64.tar.gz
RUN mv go /usr/local
RUN rm go1.12.2.linux-amd64.tar.gz

# Copy application files
COPY ./ /app
WORKDIR /app

# Configure paths for GOPATH and GOROOT
ENV GOROOT="/usr/local/go"
ENV GOPATH="/app"
ENV GOBIN="$GOPATH/bin"
ENV PATH="$PATH:$GOPATH/bin:$GOROOT/bin"

# Install Go dependencies
RUN go get github.com/creack/pty
RUN go get -d -v ./...

RUN go install -v ./...

最佳答案

这似乎与文件夹或用户权限有关。这个问题在本质上似乎是非常断断续续的。对我有用的解决方案是在你的 GOROOT 中找到这些包。或 GOPATH目录,只需手动删除它们,然后运行 ​​go get .这似乎为我解决了这个问题

关于go - 如何解决 Golang 在 golang.org/x/tools/go 中找不到包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61468003/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com