MacOS Sierra - localhost not found while using Hugo (not related to Apache)

The key to this error was the following:

127.0.0.1:1313 works, but then all of the links fail as they try to resolve back to localhost.

That gave the hint - accessing via IP works but not via hostname. Thankfully, the /etc/hosts file was also included for examination. In it we see the following line (1st line):

127.0.0.1       localhostw

The trailing "w" at the end of the hostname localhost will cause the error. In effect, localhost wasn't defined, but localhostw was.

Removing the "w" will solve the issue.