Search code examples
godependenciesgo-modules

Why am I getting error when I make a sibling module in Go?


Here's my filesystem:

Go/
  HelloWorld/
    go.mod
    go.sum
    hello.go
  GoQuote/
    go.mod

I installed the module, here's my HelloWorld/go.mod:

module example/hello

go 1.21.3

require (
    golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
    rsc.io/quote/v4 v4.0.1
    rsc.io/sampler v1.3.0 // indirect
)

and go.sum:

golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/quote/v4 v4.0.1 h1:i/LHLEinr65wwTCqlP4OnMoMWeCgnFIZFvifdXNK+5M=
rsc.io/quote/v4 v4.0.1/go.mod h1:w/DafQky66grMesu3uPhdDMS3knhBippwwemZtMOyCI=
rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

Here are the errors: could not import rsc.io/quote/v4 (cannot find package "rsc.io/quote/v4" in GOROOT or GOPATH)compilerBrokenImport and undefined: quotecompilerUndeclaredName

There were no errors until I created the GoQuote directory and ran the go mod init example.com/GoQuote command. I'm new to Go (first hour!) and don't know what the problem is.

I tried saving all my files (I'm in VS code), but it didn't work.


Solution

  • It looks like the problem was the structure of the filesystem... If I change it to be

    Go/
      go.mod
      go.sum
      hello.go
    GoQuote/
      go.mod
    

    then there are no errors.