Answer the question
In order to leave comments, you need to log in
Running a go program in VS Code without debugging gives "go: go.mod file not found in current directory". How to fix?
To learn Golang, I took VS Code as an IDE .
Added plugin for Go. Specified $GOPATH$ (a folder with projects), in which there are three folders {src, pkg, bin). Created a new *.go file in the src folder with the text of the program "Hello world!".
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}",
"args": [
"-test.run",
"MyTestFunction"
]
},
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}"
},
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
}
]
}
Answer the question
In order to leave comments, you need to log in
Googled the solution Added GO111MODULE=auto
to
Windows environment variables , restarted PC and everything worked in VS Code
You need to create a go.mod file that specifies the name of the project (based on this name, the name of the executable file is generated). The file is located in the source folder. The content of the file is very simple:
module go1
go 1.17
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question