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

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


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

Reference : Answered by Nico


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.

Tags:

Package

Eof

Go