Go failing - expected 'package', found 'EOF'

Using VS Code for GO, and faced the same issue. Saving the file 'Ctrl+S' on Windows fixed the issue.

Reference : Answered by Nico


This usually happens when you have a file e.g. foo_test.go empty or without package declaration.


Just save the file first and than run the cammand.it is working.

go run main.go


The problem wasn't neither with GOROOT nor GOPATH. The go installation failed at some point, leaving the whole thing unstable ( files created but completely empty ). When provisioning the virtual machine again, the go module checked whether the files existed. As they did, it took by granted that the installation had already take place.

A clean up and fresh installation from scratch solved the problem.


With gopls (v0.4.0 at the time of writing, so pretty unstable!) and vscode doing cmd+shift+P > Go: Restart language server worked for me.