代码之家  ›  专栏  ›  技术社区  ›  pigfox

找不到主模块;请参阅“转到帮助模块”

  •  0
  • pigfox  · 技术社区  · 5 年前

    当我从终端手动运行它时,我有以下几点:

    /app/Go/assets$ ./script.compile.wasm.sh 
    Wasm compiled
    

    文件内容为:

    #!/bin/sh
    GOOS=js GOARCH=wasm go build -o ./app.wasm ./wasm.go
    echo "Wasm compiled"
    

    wasm文件已正确编译。

    但是当我从Docker那里运行它时,我得到:

    Step 15/20 : RUN ./assets/compile.wasm.sh
     ---> Running in 38dd56259b0f
    go: cannot find main module; see 'go help modules'
    Wasm compiled
    

    编译失败。

    RUN ./assets/compile.wasm.sh
    
    0 回复  |  直到 5 年前
        1
  •  1
  •   David Maze    5 年前

    在本地情况下,您将从 assets 目录;在Dockerfile中,您是从其父目录启动它。这很重要,因为当脚本引用 ./wasm.go ,它们相对于当前目录而不是包含脚本的目录进行解析。

    资产 Dockerfile中的目录:

    # Only for this command; will reset afterwards
    RUN cd assets && ./compile.wasm.sh
    
    # For this and all following commands, unless reset with another WORKDIR
    WORKDIR /app/Go/assets
    RUN ./compile.wasm.sh