title: Not able to build go package for debugging in vscode
body: <p>Recently I have updated go debugger to dlv-dap and now I have problems debugging go packages. This is my file structure:</p>
  <p><a href="https://i.stack.imgur.com/8zrkb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8zrkb.png" alt="my file structure" /></a></p>
  <p>File contents:</p>
  <p>main.go</p>
  <pre><code>package main
  
  import (
      &quot;debugger_test/packageA&quot;
      &quot;fmt&quot;
  )
  
  func main() {
      res := packageA.DoStuff(5)
      fmt.Println(res)
  }
  </code></pre>
  <p>fileA.go</p>
  <pre><code>package packageA
  
  func DoStuff(a int) int {
      temp := a*a - 30
      return temp
  }
  
  </code></pre>
  <p>fileA_test.go</p>
  <pre><code>package packageA
  
  import (
      &quot;testing&quot;
  
      &quot;github.com/stretchr/testify/assert&quot;
  )
  
  func TestStuff(t *testing.T) {
      arg := 2
      res := DoStuff(arg)
      assert.Equal(t, -26, res)
  }
  </code></pre>
  <p>launch.json:</p>
  <pre><code>    &quot;version&quot;: &quot;0.2.0&quot;,
      &quot;configurations&quot;: [
          {
              &quot;name&quot;: &quot;Test&quot;,
              &quot;type&quot;: &quot;go&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;mode&quot;: &quot;test&quot;,
              &quot;program&quot;: &quot;${fileDirname}&quot;,
              &quot;substitutePath&quot;: [
                  {
                      &quot;from&quot;: &quot;/home/vlasov&quot;,
                      &quot;to&quot;: &quot;/opt/storage&quot;,
                  },
              ],
          },
          {
              &quot;name&quot;: &quot;Main&quot;,
              &quot;type&quot;: &quot;go&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;mode&quot;: &quot;debug&quot;,
              &quot;program&quot;: &quot;${fileDirname}&quot;,
              &quot;substitutePath&quot;: [
                  {
                      &quot;from&quot;: &quot;/home/vlasov&quot;,
                      &quot;to&quot;: &quot;/opt/storage&quot;,
                  },
              ],
          }
      ]
  }
  </code></pre>
  <p>This used to work just fine before dlv-dap. Now when I try to debug I get this message:</p>
  <pre><code>Starting: /home/vlasov/go/bin/dlv-dap dap --listen=127.0.0.1:46369 --log-dest=3
  DAP server listening at: 127.0.0.1:46369
  Build Error: go test -c -o /opt/storage/debugger_test/packageA/__debug_bin -gcflags all=-N -l /home/vlasov/debugger_test/packageA
  directory /home/vlasov/debugger_test/packageA outside available modules (exit status 1)
  </code></pre>
  <p>A partial fix I was able to find is to change <code>${fileDirname}</code> to <code>${fileDirname}/main.go</code>, however this way debugger does not hit breakpoints in main.go. This method does not work for tests, I still get similar message with <code>&quot;program&quot;: &quot;${fileDirname}/fileA_test.go&quot;</code>.</p>
  <p>What is the correct way to configure launch.json to be able to run debug tests and packages normally?</p>