Fixing “Invalid date” Jekyll build failure on Netlify
Update: This was unintentionally broken by a bad rollout at Netlify which has since been fixed. There is no longer any need to add the cache directory to the exclude list.
This blog is built using Jekyll and hosted on Netlify. Most of the time, the publishing workflow is straightforward: I write a post in my editor, commit it, push to GitHub, and Netlify picks up the change, builds a new set of static pages, and publishes them.
But not yesterday. Yesterday, I wrote a post, pushed it, and nothing happened. On further investigation, the site generation process had failed with a new error:
Error: could not read file /opt/build/repo/cache/bundle/ruby/3.0.0/gems/jekyll-4.2.0/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb: Invalid date '<%= Time.now.strftime('%Y-%m-%d %H:%M:%S %z') %>'
That was odd. Why would it be trying to process a template file from the
directory, of all places? I wasn’t alone in experiencing this new
The suspicious thing to me was the path: Jekyll already knows not to look in
vendor directory, and in the past, that’s where gems were installed
during the build process.
But now, they aren’t. Something has changed at Netlify, and the gems are now
installed under the
cache directory, which Jekyll doesn’t know to ignore.
We can easily fix that, however. In
_config.yml, there’s a commented-out
section that says:
# Exclude from processing. # The following items will not be processed, by default. Create a custom list # to override the default setting.
To add the
cache directory, we just need to uncomment the
and add a new entry, so that it looks like this:
exclude: - Gemfile - Gemfile.lock - node_modules - vendor/bundle/ - vendor/cache/ - vendor/gems/ - vendor/ruby/ - cache/
And now it works again, as you can see because you’re reading this.
Here’s a bonus hint that you might need if you’ve tried updating your gems in a vain effort to solve the problem and are now seeing this type of error:
Activating bundler (~> 2.3) failed: Could not find 'bundler' (2.3.16) required by your /opt/build/repo/Gemfile.lock.
The simplest fix is to delete the
BUNDLED WITH section from your
Gemfile.lock. I’m sure it means well, but that feature has caused me far more
problems than it’s ever solved.