hugo version)?Hugo Static Site Generator v0.74.1/extended darwin/amd64 BuildDate: unknown
I have a baseof.html with {{ partialCached "header-static.html" . }} and header-static.html with
{{ $jsOpts := dict "minify" true "targetPath" "/js/main.js" }}
{{ $mainJS := resources.Get "js/entrypoints/main.js" | js.Build $jsOpts }}
{{ $mainJS = $mainJS | babel | minify | fingerprint }}
<script src='{{ $mainJS.RelPermalink }}' async></script>
<script nomodule>
console.warn("could not load enhancements");
document.body.classList.add("has-old-js");
</script>
{{ $jsOpts = dict "minify" true "targetPath" "/js/enhancements.js" }}
{{ $js := resources.Get "js/esbuild/enhancements.js" | js.Build $jsOpts }}
{{ $js = $js | minify | fingerprint }}
<script src='{{ $js.RelPermalink }}' type="module" async></script>
This configuration builds fine with hugo.
However, when I run hugo server, the server starts and the pages load seemingly normally, but I get error messages in my terminal:
Change detected, rebuilding site.
2020-07-16 10:35:03.566 -0400
Template changed "/Users/adhoc/src/spl/poor-richard/layouts/partials/header-static.html": CREATE
ERROR 2020/07/16 10:35:03 render of "page" failed: execute of template failed: template: _default/single.html:16:5: executing "_default/single.html" at <partialCached "header-static.html" .>: error calling partialCached: "/Users/adhoc/src/spl/poor-richard/layouts/partials/header-static.html:3:55": execute of template failed: template: partials/header-static.html:3:55: executing "partials/header-static.html" at <js>: can't evaluate field Build in type string
ERROR 2020/07/16 10:35:03 render of "home" failed: execute of template failed: template: _default/index.html:16:5: executing "_default/index.html" at <partialCached "header-static.html" .>: error calling partialCached: "/Users/adhoc/src/spl/poor-richard/layouts/partials/header-static.html:3:55": execute of template failed: template: partials/header-static.html:3:55: executing "partials/header-static.html" at <js>: can't evaluate field Build in type string
ERROR 2020/07/16 10:35:03 render of "page" failed: execute of template failed: template: _default/single.html:16:5: executing "_default/single.html" at <partialCached "header-static.html" .>: error calling partialCached: "/Users/adhoc/src/spl/poor-richard/layouts/partials/header-static.html:3:55": execute of template failed: template: partials/header-static.html:3:55: executing "partials/header-static.html" at <js>: can't evaluate field Build in type string
ERROR 2020/07/16 10:35:03 render of "page" failed: execute of template failed: template: _default/single.html:16:5: executing "_default/single.html" at <partialCached "header-static.html" .>: error calling partialCached: "/Users/adhoc/src/spl/poor-richard/layouts/partials/header-static.html:3:55": execute of template failed: template: partials/header-static.html:3:55: executing "partials/header-static.html" at <js>: can't evaluate field Build in type string
Total in 73 ms
ERROR 2020/07/16 10:35:03 Rebuild failed:
ERROR 2020/07/16 10:35:03 Failed to render pages: render of "page" failed: execute of template failed: template: thanks-page/single.html:16:5: executing "thanks-page/single.html" at <partialCached "header-static.html" .>: error calling partialCached: "/Users/adhoc/src/spl/poor-richard/layouts/partials/header-static.html:3:55": execute of template failed: template: partials/header-static.html:3:55: executing "partials/header-static.html" at <js>: can't evaluate field Build in type string
Change detected, rebuilding site.
2020-07-16 10:35:04.172 -0400
Template changed "/Users/adhoc/src/spl/poor-richard/layouts/partials/header-static.html": CREATE
Total in 119 ms
You probably don't need Babel on top of js.Build. You can use the target option on js.Build instead. Hope this solves your problem.
I had the issue apart from Babel.
A) I tested 0.74.2, and the issue is still there.
B) ESBuild target only supports going back to ES6. Since I'm still trying to send main.js to IE11 (which is ES5), I still need Babel for that. Another quick test revels that Babel isn't really a factor in the error.
It seems like things initially build correctly and then something comes along after the fact and fails. Maybe there's a race somewhere?
The thing is, I see what the error says, but I have no idea how js would end up to be a string.
Any idea, @moorereason ?
I've tried searching my codebase for anything else named js that might be confusing it, but the only thing even close is the $js resource and changing its name doesn't help.
@bep, it doesn't make sense to me either.
@carlmjohnson, can you create the simplest test site possible that replicates this issue?
I'll see what I can do. In the meanwhile, the full repo is public if you want to try yourself: http://github.com/spotlightpa/poor-richard/
😆 Ugh, you'll never believe how dumb this is.
I was hacking away, trying to get a minimal example, so I was killing and restarting hugo server as I tried different things out. Different configs, different file locations, import cycles. Nothing works. They all load fine in browser but then a mysterious error message shows up in Terminal tab afterwards…
At one point, I had killed the server and kept change files around to try something else and went back to Terminal to restart and I had gotten the error message again. That shouldn't be possible, right? 🤔
So, sure enough I ran ps aux | grep hugo and there it was some kind of phantom process that must have gotten stuck in the background and never killed. I guess it also for some reason was binding a port other than 1313 or I definitely would have figured it out sooner. I imagine it was Hugo 0.68 or whatever I was running before I upgraded to 0.74, and it just managed to survive in zombie mode for the better part of a week!
Anyway, I killed that and it appears the problem is solved! Sorry for wasting everyone's time with this one. 😠Thanks for your help. Next time, I'll do what the people on the support line say and restart my computer before opening a ticket. 🤣
ESBuild target only supports going back to ES6.
They have now added a es5 target (merged in Hugo now). I don't think they convert newer syntax to es5, though.
Most helpful comment
😆 Ugh, you'll never believe how dumb this is.
I was hacking away, trying to get a minimal example, so I was killing and restarting
hugo serveras I tried different things out. Different configs, different file locations, import cycles. Nothing works. They all load fine in browser but then a mysterious error message shows up in Terminal tab afterwards…At one point, I had killed the server and kept change files around to try something else and went back to Terminal to restart and I had gotten the error message again. That shouldn't be possible, right? 🤔
So, sure enough I ran
ps aux | grep hugoand there it was some kind of phantom process that must have gotten stuck in the background and never killed. I guess it also for some reason was binding a port other than 1313 or I definitely would have figured it out sooner. I imagine it was Hugo 0.68 or whatever I was running before I upgraded to 0.74, and it just managed to survive in zombie mode for the better part of a week!Anyway, I killed that and it appears the problem is solved! Sorry for wasting everyone's time with this one. 😠Thanks for your help. Next time, I'll do what the people on the support line say and restart my computer before opening a ticket. 🤣