-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The "defines" js.Build option fails silently for almost anything besides single alphanumeric words #8040
Comments
This smells like an upstream issue (in the ESBuild project) -- we just pass these defines on as-is -- and I would somehow expect them to validate these. |
I was curious to see what this problem was so I took a look. It looks like the code for processing errors from esbuild tries to access hugo/resources/resource_transformers/js/build.go Lines 100 to 101 in 212e5e5
I assume this then leads to a crash in Hugo's code:
The define feature is documented here: https://esbuild.github.io/api/#define. The key must be a valid JavaScript identifier or identifier chain, and the value must either be a valid JavaScript identifier or a JSON value. |
This was resolved in v0.81.0 with a1fe552. |
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. |
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
Yes.
Summary
When using the
"defines"
option withjs.Build
many special characters such as-
,<
, and!
, as well as any internal spaces, will causejs.Build
to return anil
reference without throwing any error. The build will later fail when you try to insert the link to the resource into your layout file with$myBuiltJS.RelPermalink
.EG:
The issue is two-fold here:
js.Build
just fails so easily that it's really hard to use it for anything other than the very most basic substitutions. I assume (and hope) that this is not the intended behavior.js.Build
itself, the resulting build failure is very confusing and there is no easy way to tell that a) The problem even came from "defines" in the first place, and b) what about the provided value to "defines" caused it to fail.I spun up a fresh Hugo repo to demonstrate this issue. Check out the
index.html
layout to see various exampled of passing and failing values for "defines". (You'll have to un-comment each one individually to see.)https://github.com/LandGod/HugoTestBed
The text was updated successfully, but these errors were encountered: