Hugo 0.50 fails when --minify is enabled on content that worked fine in hugo 0.48


#1

For context, under 0.4.8 I typically built my personal blog with the following flags:

hugo  --verbose --templateMetrics --templateMetricsHints --minify --theme=casper

The --minify flag seems to consistently cause a failure that does not happen without it (see examples below). I iterated through combinations of all flags to confirm the --minify was problematic. No other flag triggers an error unless --minify is enabled.

Interestingly, the exact point of failure with --minify enabled varies with each run. The following examples were done without any changes to the underlying content:

$ hugo --minify --theme=casper
Building sites … ERROR 2018/11/05 14:34:00 parse error:9:16: unexpected comma character outside an array or object
    9:     "@type": "Article",
                      ^
ERROR 2018/11/05 14:34:00 parse error:3:88: unexpected comma character outside an array or object
    3:     <link rel="canonical" href="https://maisonbisson.com/post/in-the-window-at-bobs-donuts/" />
                                                                                              ^
ERROR 2018/11/05 14:34:00 parse error:7:11: unexpected comma character outside an array or object
    7:         "sameAs": [
                 ^
ERROR 2018/11/05 14:34:00 parse error:5:15: unexpected comma character outside an array or object
    5:     <link rel="apple-touch-icon" sizes="167x167" href="/images/touch-icon-ipad-pro.png">
                     ^
Total in 15828 ms
Error: Error building site: failed to render pages: parse error:8:23: unexpected comma character outside an array or object
    8:     "@context": "https://schema.org",
                             ^

and…

$ hugo --minify --theme=casper
Building sites … ERROR 2018/11/05 14:35:46 parse error:9:16: unexpected comma character outside an array or object
    9:     "@type": "Article",
                      ^
ERROR 2018/11/05 14:35:46 parse error:5:51: unexpected comma character outside an array or object
    5:     <meta property="article:tag" content="Olympus OM10" />
                                                         ^
ERROR 2018/11/05 14:35:46 parse error:8:8: unexpected comma character outside an array or object
    8:             "@type": "ImageObject",
              ^
ERROR 2018/11/05 14:35:46 parse error:6:14: unexpected comma character outside an array or object
    6:         "logo": https://maisonbisson.com/images/icon.png
                    ^
Total in 14098 ms
Error: Error building site: failed to render pages: parse error:5:25: unexpected comma character outside an array or object
    5:     <meta property="article:tag" content="olympus c8080" />
                               ^

and…

$ hugo --minify --theme=casper
Building sites … ERROR 2018/11/05 14:36:08 parse error:8:28: unexpected comma character outside an array or object
    8:     "@context": "https://schema.org",
                                  ^
ERROR 2018/11/05 14:36:08 parse error:6:10: unexpected comma character outside an array or object
    6:     "author": {
                ^
ERROR 2018/11/05 14:36:08 parse error:7:46: unexpected comma character outside an array or object
    7:     <link rel="canonical" href="https://maisonbisson.com/post/twin-beech-beatty-nv/" />
                                                    ^
ERROR 2018/11/05 14:36:08 parse error:10:38: unexpected comma character outside an array or object
   10:           <link href="/index.xml" rel="alternate" type="application/rss+xml" title="MaisonBisson" />
                                            ^
Total in 14197 ms
Error: Error building site: failed to render pages: parse error:8:20: unexpected comma character outside an array or object
    8:     "@context": "https://schema.org",
                          ^

and…

$ hugo --minify --theme=casper
Building sites … ERROR 2018/11/05 14:33:40 parse error:3:94: unexpected comma character outside an array or object
    3:     <link rel="canonical" href="https://maisonbisson.com/post/willie-christiana-copenhagen/" />
                                                                                                    ^
ERROR 2018/11/05 14:33:40 parse error:1:134: unexpected comma character outside an array or object
    1: 623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.
                                                                                                                                            ^
ERROR 2018/11/05 14:33:40 parse error:9:18: unexpected comma character outside an array or object
    9:     "@type": "Article",
                        ^
ERROR 2018/11/05 14:33:40 parse error:7:46: unexpected comma character outside an array or object
    7:     <link rel="canonical" href="https://maisonbisson.com/post/twin-beech-beatty-nv/" />
                                                    ^
Total in 16566 ms
Error: Error building site: failed to render pages: parse error:7:4: unexpected comma character outside an array or object
    7:         
          ^

Here’s a successful run, just for more context:

$ hugo --theme=casper

                   |  EN    
+------------------+-------+
  Pages            | 28957  
  Paginator pages  |  1772  
  Non-page files   |  2669  
  Static files     |    45  
  Processed images |  2065  
  Aliases          | 14508  
  Sitemaps         |     1  
  Cleaned          |     0  

Total in 22739 ms

#2

Can you share your site code, or create a sample repo, to where we can attempt to reproduce this issue?


#3

Yes, I should have provided that in my initial post.

I was able to reproduce the error in a completely new setup. The repo is here: https://github.com/misterbisson/hugo-050-bug-repo

I created that by doing a hugo new site..., and cloning the theme from https://github.com/vjeantet/hugo-theme-casper. The config.toml is an anonymized version of my own config.toml (with only a few items removed).

I also realize I should have added:

$ hugo version
Hugo Static Site Generator v0.50/extended darwin/amd64 BuildDate: unknown

The errors have been reproduced on my laptop and in Wercker, where I do my “production” builds (both are running v0.50).


#4

Cloned your repo and I’m able to reproduce the issue, and I also see how it errors out on a different area each time.

One reason for the errors is the JSON in your generated /index.html – it is invalid.

You can see this if you run your site without the --minify flag, and inspect the JSON. There is a missing value after the "name" key.

{
    "@context": "https://schema.org",
    "@type": "Website",
    "publisher": {
        "@type": "Person",
        "name": ,
        
        "url": https://example.com,
        "sameAs": [
            
        ]
    },
    "url": https://example.com,
    "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": https://example.com
    },
    "description": a bunch of stuff I would have emailed you about
}

This is likely because the partial that builds this JSON at themes/casper/layouts/partials/semantic.html does not use a default fallback value for this line

"name": {{ .Site.Params.authorname }},

Or, that param is not specified in your config.toml.


Update: Once I added this to your config.toml:

[params]
  authorname = "Some Name"

I was able to successfully build the site using your command flags:

hugo  --verbose --templateMetrics --templateMetricsHints --minify --theme=casper

#5

Welp! Thanks for pointing that out. I had done a lot of validation, but I’m realizing I didn’t attempt to validate the schema.org bits.

Confirmed. Just as in the example I provided, I have a .Site.Params.author, but not .Site.Params.authorname in my config.

The theme does have some inconsistencies in the variable names, that’s clearly another that needs cleaning.


#6

Looks like i’m seeing the same thing on my site. I can see I’m probably using a very similar bit of code (theme available here) to generate the schema json.

The thing is I’m not really able to figure out what the offending code is. None of the error messages given point me at an error I can recognise.

Is there anything that can be done to improve the error messages? Or at least, some pointers so I can figure out where to look?


#7

@mrwonka – Please open a new thread under “support” topic and then reference this thread. Thanks.


#8

I’ve just figured it out :smile: Typical!

Steps to reproduce a solution:

  1. Run hugo --minify a bunch of times and attempt to identify a page where the error is happening.
  2. Run a standard hugo and navigate to that page.
  3. Take that pages schema.org json and run it in an online validator.
  4. See that I should have put a | plainify in when I output "description": "{{ .Summary }}"

#9

Thanks a lot for giving the perfect answer.


#10

Glad it helped :+1: