hugo: Mage failing with "undefined: mg.Context" error
All mage commands (except mage -h) in the hugo source directory fail with the exact same error output:
mage hugo
# command-line-arguments
./mage_output_file.go:330:17: undefined: mg.Context
Error: error compiling magefiles
mage install
# command-line-arguments
./mage_output_file.go:330:17: undefined: mg.Context
Error: error compiling magefiles
mage -l
# command-line-arguments
./mage_output_file.go:330:17: undefined: mg.Context
Error: error compiling magefiles
I even tried with a clean GO environment, following all the steps in CONTRIBUTING.md
exactly, with the same result.
I ran mage -keep
to diagnose the problem. The resulting mage_output_file.go is attached. Line 330 is ctx, cancel := mg.Context()
, indicating that for some reason the Context func in the mg package can’t be linked even though I confirmed it was there.
I can’t tell if this is a flaw with mage or the hugo source. I was able to run mage -l
and mage build
from the ~/go/src/github.com/magefile/
directory, so I’m pretty sure my mage installation is sound.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (13 by maintainers)
Ahh, this is the problem: https://github.com/gohugoio/hugo/blob/master/Gopkg.toml#L29
The vendor directory is pinned at v1, but the versions of mage that are running are generating code that expects to be able to reference libraries from v2.
This is kind of a backwards compatibility problem. We may need a version number in the magefile so mage can know what version of the main file to generate.
Btw, just for sake of completeness, there’s a new fix to mage’s own build script to run
go install
with the-a
option so that it won’t no-op if mage was already built withgo get
(this was confusing when you usedgo get
and then tried tomage build
), and there’s new and better install instructions:(of course
go get
and thenmage build
also works)The v2.0.1 binary release incorporates this fix: https://github.com/magefile/mage/releases/tag/v2.0.1
Fix confirmed.
This is now fixed in master of mage. I’ll get a new binary built with the fix ASAP.
Note that this does not fix the fact that if you reference libraries in your magefile then you need to have those libraries on your local machine. But it at least fixes the backwards compatibility problem introduced recently that creates the mg.Context error. i.e. using the mage v2 binary with mage v1 libraries vendored.
Please retest with current master. I tested locally with hugo and could repro the problem before / not repro the problem after, but I would like independent confirmation.
Trust me, I tried that (and just did again) and everything else outside of what a go/mage expert my try. Has anyone tried doing building hugo from a completely clean (from scratch) go environment?
You likely need to install a new
mage
(using...
in yourgo get
command).