gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.73k stars 7.53k forks source link

Make the "is this a Hugo Module" logic more lenient #6299

Closed espadrine closed 5 years ago

espadrine commented 5 years ago

Reproduction

  1. Start with a folder in which hugo server does serve the website.
  2. touch go.mod
  3. hugo server

Expected behavior

Hugo serves the website still.

Actual behavior

Hugo fails to serve the website with the following error:

go: cannot determine module path for source directory ~/go/src/example.com/nuclear/reactor (outside GOPATH, no import comments)
Error: failed to download modules: go command failed: go: cannot determine module path for source directory ~/go/src/example.com/nuclear/reactor (outside GOPATH, no import comments)

(More commonly, the go.mod will not actually be empty; the render may then fail with the message go: error loading module requirements for instance, which feels like it ought to be decoupled.)

Use case

We have a project where we maintain the documentation alongside the code. Had we developed the project in any other language than Go, we would have had no issue. But the project is in Go, and therefore we now started to work on supporting Go modules, which required having a go.mod. Old versions of Hugo worked fine (such as v0.54.0), but new versions don't.

References

Hugo Static Site Generator v0.57.2/extended darwin/amd64 BuildDate: unknown

bep commented 5 years ago

I suggest you move your site into its own root.

espadrine commented 5 years ago

It does look pretty heavily hardcoded. IIUC it would be subtle to detect whether the go.mod is a Hugo module or something else. Oh well.

Thanks for your work on Hugo! You may close this issue if you believe it would be impossible to fix.

bep commented 5 years ago

You may close this issue if you believe it would be impossible to fix.

I didn't say that, I just gave you a tip for a workaround.

What we cannot currently do is change it to hugo.mod or something (that would be nice, but go.mod is hardcoded in 123 different places in the Go source).

What we could probably do is to improve the "is this a Hugo Module" logic.

Currently, it is simply: Is there a go.mod file in the project.

We could probably change that to "go.mod + any module imports (e.g. theme imports with module paths)".

espadrine commented 5 years ago

Nicely done! Thanks a lot!

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.