title: How to fix Go build error "can't load package" with Go modules?
body: <p>I'm setting up a new project using Go modules with <a href="https://bogotobogo.com/GoLang/GoLang_Modules_1_Creating_a_new_module.php" rel="noreferrer">this tutorial</a>, and then trying to build it.</p>
  
  <p>The module is located in a folder outside of the $GOPATH with the following structure:</p>
  
  <pre><code>example.com
  ├── my-project
  ├── ├── main
  ├── ├── ├── main.go
  ├── ├── go.mod
  </code></pre>
  
  <p>I've run <code>go mod init example.com/my-project</code> in directory <code>example.com/my-project</code> and created the go.mod file shown above.</p>
  
  <p><code>main.go</code> has basic contents:</p>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
  "fmt"
  )
  func main(){
   fmt.Println("Hello, world!")
  }
  </code></pre>
  
  <p>After attempting to run <code>go build</code> in directory <code>example.com/my-project</code>, I receive the following error message:</p>
  
  <p><code>can't load package: package example.com/my-project: unknown import path "example.com/my-project": cannot find module providing package example.com/my-project</code>.</p>
  
  <p>I've also attempted to run <code>go build</code> in directory <code>/</code>, outside of <code>example.com/my-project</code>, and I get similar, failing results:</p>
  
  <p><code>can't load package: package .: no Go files in ...</code></p>
  
  <p>I'm probably getting some basic thing wrong, so thanks for your patience and any help you can give.</p>