Build fails on Netlify, works locally

Any ideas why this may be failing on Netlify deploy, but building fine locally?

Netlify build log:

7:24:52 PM: Netlify Build                                                 
7:24:52 PM: ────────────────────────────────────────────────────────────────
7:24:52 PM: ​
7:24:52 PM: ❯ Version
7:24:52 PM:   @netlify/build 29.53.0
7:24:52 PM: ​
7:24:52 PM: ❯ Flags
7:24:52 PM:   accountId: 593ef9cea700c425465b0667
7:24:52 PM:   baseRelDir: false
7:24:52 PM:   buildId: 66c525a74664ad0008c2b642
7:24:52 PM:   deployId: 66c525a74664ad0008c2b644
7:24:52 PM: ​
7:24:52 PM: ❯ Current directory
7:24:52 PM:   /opt/build/repo
7:24:52 PM: ​
7:24:52 PM: ❯ Config file
7:24:52 PM:   /opt/build/repo/netlify.toml
7:24:52 PM: ​
7:24:52 PM: ❯ Context
7:24:52 PM:   production
7:24:53 PM: ​
7:24:53 PM: ❯ Loading plugins
7:24:53 PM:    - @netlify/plugin-lighthouse@6.0.0 from Netlify app
7:24:55 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
7:24:54 PM: ​
7:24:54 PM: build.command from netlify.toml                               
7:24:54 PM: ────────────────────────────────────────────────────────────────
7:24:54 PM: ​
7:24:54 PM: $ curl -LJO https://github.com/sass/dart-sass/releases/download/1.77.8/dart-sass-1.77.8-linux-x64.tar.gz && tar -xf dart-sass-1.77.8-linux-x64.tar.gz && rm dart-sass-1.77.8-linux-x64.tar.gz && export PATH=/opt/build/repo/dart-sass:$PATH && hugo --gc --minify 
7:24:54 PM:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
7:24:54 PM:                                  Dload  Upload   Total   Spent    Left  Speed
7:24:54 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
7:24:54 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
7:24:55 PM: 100 3673k  100 3673k    0     0  12.1M      0 --:--:-- --:--:-- --:--:-- 12.1M
7:24:55 PM: curl: Saved to filename 'dart-sass-1.77.8-linux-x64.tar.gz'
7:24:55 PM: Start building sites …
7:24:55 PM: hugo v0.133.0-c9777473d1369f812d727a6c07dc57ad7be7bf62+extended linux/amd64 BuildDate=2024-08-17T19:57:41Z VendorInfo=gohugoio
7:24:55 PM: Total in 164 ms
7:24:55 PM: Error: error building site: process: readAndProcessContent: "/opt/build/repo/content/library/ratings/tv/_content.gotmpl:20:32": template: /opt/build/repo/content/library/ratings/tv/_content.gotmpl:20:32: executing "/opt/build/repo/content/library/ratings/tv/_content.gotmpl" at <time.AsTime>: error calling AsTime: unable to parse date: 1 Jan 1970
7:24:55 PM: ​
7:24:55 PM: "build.command" failed   

Here is the offending line, according to the above log (with accompanying previous line):

{{ $t := time (.year | int) }}
{{ $dates := dict "date" (time.AsTime (time.Format "2 Jan 2006" $t)) }}

Here is the portion of the JSON that the content adapter is referring to:

...
"year": 2006,
...

Before digging into the behavioral differences between remote and local builds, the code snippet above, if it worked the way you want, would perform unnecessary type conversions:

float → int → time.Time → string → time.Time

But the first problem is trying to parse a 4 digit integer, intended to be a year, as a date:

{{ 2023 | int | time.AsTime | warnf "%#[1]v (%[1]T)" }}

That produces:

time.Date(1969, time.December, 31, 16, 33, 26, 0, time.Local) (time.Time)

…which is clearly not what you want.

Assuming you want to treat “2023” as “January 1, 2023”, do something like:

{{ printf "%v-01-01" 2023 | time.AsTime }}
1 Like

I really just want to retrieve the year as a number that I’m printing and ifing against.

Also, why would Hugo local not flag this as an issue?

Then why are you trying to assign it to a date field?

That’s a holdover from me adapting the example from the Content Adapters doc page:

{{ $dates := dict "date" (time.AsTime .date) }}

Then don’t do that. Instead, map the value to a custom front matter parameter.

Ok, I removed that offending code and we’re good now. Thank you.

1 Like

Are you sure you’re using the same Hugo version locally and in Netlify?

Yes, both were using 0.133.0

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.