【问题标题】:How to resolve Golang cannot find packages in golang.org/x/tools/go?如何解决 Golang 在 golang.org/x/tools/go 中找不到包?
【发布时间】:2020-04-27 20:36:41
【问题描述】:

这个问题只是在构建之间随机出现,现在甚至我们的生产 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 ./...

【问题讨论】:

    标签: go dockerfile


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      看来解决方法是将“go get -d -v ./...”更改为“go get”

      另外,关于为什么在我们的生产版本上发生这种情况而没有对其进行更改,我们没有使用任何包版本控制,并且更新了外部包导致此错误。因此,经过一番调查,我们可能应该使用 go 模块来处理版本控制。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多