0

Have been trying to configure go on my laptop for some time now, keep running into errors like $GOPATH/go.mod exists but should not on powershell when prompted with go emv .

go version go1.21.0 windows/amd64

"Error loading workspace folders (expected 1, got 0) failed to load view for" is the error I keep getting is Visual Studio Code:

error screenshot

I'm very new to go, I have it configured on my main system perfectly so I am very confused on why it seems to be giving me so much trouble on my laptop. I have looked at every other stack overflow post I can find relating to this and none have seemed to help my issue.

p.s settings.json keeps going blank after there was code in it. I am also getting this error when trying to do go run.\main.go

go : The term 'go' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling 
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ go run .\main
+ ~~
    + CategoryInfo          : ObjectNotFound: (go:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException"
Brits
  • 14,829
  • 2
  • 18
  • 31
  • What is `GOPATH` set to? (run `go env` to check). [This answer](https://stackoverflow.com/a/72709319/11810946) may help. Ref your "is not recongized" issue it looks like Go is not in your path; the [installer](https://go.dev/doc/install) generally does this for you (to add manually [see this answer](https://stackoverflow.com/a/4493004/11810946) and substitute the path where go is installed - probably `C:\Program Files\Go\bin`). – Brits Sep 01 '23 at 02:35
  • go env "$GOPATH/go.mod exists but should not". I followed the steps for both of the other answers you posted including trying to substitute the path where go is installed. – Brody Scott Sep 01 '23 at 03:25
  • going to try again in the morning with a fresh install of everything I appreciate the reply :) – Brody Scott Sep 01 '23 at 03:30
  • OK - Check if the environment variable `GOPATH` is set (in powershell run `$Env:GOPATH`) if so look in that folder; if not look in the `go` folder in the path returned by `$Env:USERPROFILE` (i.e. the Go folder off your profile folder). There is probably a `go.mod` file in that folder. Either remove that file or change the `GOPATH` environmental variable to point to another folder. Reinstalling Go will probably not fix this (as the `GOPATH` will not change). – Brits Sep 01 '23 at 05:29
  • Finally figured it out, you were spot on in the go folder there was a file just named "go" that for some reason had the video icon on it, once I removed it everything works in Visual Studio now!!! Thanks so much, this probably would've taken me forever without your help :) – Brody Scott Sep 01 '23 at 21:22
  • Windows hides file extensions by default; I'd suggest [turning that option off](https://support.microsoft.com/en-us/windows/common-file-name-extensions-in-windows-da4a4430-8e76-89c5-59f7-1cdbbc75cb01). It sounds like the `.mod` extension is associated with a movie player ([see here](https://support.microsoft.com/en-us/windows/change-default-programs-in-windows-e5d82cad-17d1-c53b-3505-f10a32e1894d#ID0EDD=Windows_11) for help changing that - but it's not normally an issue as you will be using VS Code, or similar, to edit the files). – Brits Sep 01 '23 at 23:49
  • Awesome will do, thanks again! – Brody Scott Sep 02 '23 at 00:16
  • Does this answer your question? [VS Code Go: $GOPATH/go.mod exists but should not](https://stackoverflow.com/questions/62177371/vs-code-go-gopath-go-mod-exists-but-should-not) – Zephyr Sep 02 '23 at 11:27

0 Answers0