1

New to Go, I recently installed it via brew (brew install go) on my mac, which is running on version 1.20.5. I then installed the Go extension (v0.39.0) in VSCode as recommended in order to start on some tutorials.

With the setup done, I jumped straight into the 'Getting Started' tutorial on the Go site. As soon as I create a .go file I get the following error at the bottom status bar in VSCode:

Error loading workspace: packages.Load error: err: exit status 1: stderr: go: no modules were found in the current workspace; see 'go help work'
Source: Go (Extension)

I was not prompted to install any missing dependencies. I pressed on with the tutorial and all runs as expected, however the error lingers in the bottom status bar. This is the same for all Go projects I have tried to start so far.

To try remedy the issue, I tried to uninstall both the VSCode extension as well as Go from my computer and reinstall without success. I have also tried to search similar issues but cannot find anything on stackoverflow or in the extension issues for VSCode. The GOPATH and GOROOT appear to be set up correctly. I have updated the GO111MODULE environment to go env -w GO111MODULE=auto as it was previously blank. This is the only environment change I have made.

Would appreciate any help to resolve this.

Jacqui
  • 21
  • 3
  • Hope this helps https://stackoverflow.com/questions/66894200/error-message-go-go-mod-file-not-found-in-current-directory-or-any-parent-dire – PRATHEESH PC Jun 27 '23 at 06:03
  • Thank you for sharing. Unfortunately it doesn't help. If I change the GO111MODULE to 'off' I get a different error: `Error loading workspace: You are outside of a module and outside of $GOPATH/src. If you are using modules, please open your editor to a directory in your module.` – Jacqui Jun 27 '23 at 10:10
  • The error indicates that it is not able to find any module in the current workspace. Do you have `go.mod`? Did you tried `go mod init `? – PRATHEESH PC Jun 27 '23 at 10:21
  • Yes, I set up the go.mod file. When I run `go mod init ` it returns a message saying the go.mod file already exists – Jacqui Jun 28 '23 at 00:56

1 Answers1

-1

After running ls in the main go folder (the folder holding my go projects) I found there was a "go.work" file that seemed to be corrupting everything. I must have made the file in error as I have not had the need to use "go.work" files yet.

After deleting this file my code now runs properly (I hadn't addressed this issue yet) and I have no VSCode error. I am unsure why I created it to start with but glad it's resolved.

Jacqui
  • 21
  • 3
  • Typically, in a Go project, you would have a Go module file named "go.mod" at the root of your project directory. The "go.mod" file manages the dependencies and versioning for your project. If you have a file named "go.work" in your Go folder, it could be a custom file created by you or your project team. – hkanjih Jun 30 '23 at 17:48
  • Thanks @hkanjih. I re-read my solution above and realised it wasn't so clear and updated it for clarity sake. That was the first go file/project I worked on so didn't have the need for "go.work" files yet. At least it's given me better understanding of both files and what they are used for. – Jacqui Jul 03 '23 at 06:30