Runar Ovesen Hjerpbakk

Software Philosopher

Jekyll - does not have a valid date in the YAML front matter

I’ve now encountered this problem twice and had to DuckDuckGo it both times, so here is the blogpost.

When building a Jekyll website from a template for the first time, some templates will give the following error:

Error: could not read file /srv/jekyll/tmp/gems/jekyll-3.8.5/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb: Invalid date ‘<%= Time.now.strftime(‘%Y-%m-%d %H:%M:%S %z’) %>’: Document ‘tmp/gems/jekyll-3.8.5/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb’ does not have a valid date in the YAML front matter.
ERROR: YOUR SITE COULD NOT BE BUILT:
————————————
Invalid date ‘<%= Time.now.strftime(‘%Y-%m-%d %H:%M:%S %z’) %>’: Document ‘tmp/gems/jekyll-3.8.5/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb’ does not have a valid date in the YAML front matter.

The error will say something about an invalid date, and sure, year zero existed in the time before blogs, but that’s not the real issues.

Your site could not be built

Looking closer at the error, we can see that the post exists under the tmp directory. This directory contains temporary artifacts used during the build, but not your actual content. The post in question is a how-to post from the default Jekyll template and nothing in tmp should be consider an actual part of your site.

To fix this, simply add the tmp directory to the list of excludes in your _config.yml:

exclude:
  - tmp/
  - vendor/
  - Gemfile
  - Gemfile.lock
  - ...

And voila, the site builds!