Jekyll won't build site due to error: invalid date in vendor
May 01, 2020 | Jameson ZimmerThe frustrating thing about web development tools is that if you don’t touch a site for a long time, chances are you’ll find dependency issues when you come back to it.
In Jekyll, those dependency issues usually relate to Bundler, the tool of choice for managing the gems, Ruby versions, and other “dependencies” needed to run your site.
If you’re reading this post, you probably are Googling a Terminal error related to “invalid date” for your Jekyll site… even though all the dates in your _posts folder appear to be properly structured. (YYYY-MM-DD-title-of-post.md
.)
It probably looks something like this:
Error: could not read file [PATH TO YOUR PROJECT]/vendor/bundle/ruby/2.5.0/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 'vendor/bundle/ruby/2.5.0/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 'vendor/bundle/ruby/2.5.0/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.
You’re probably seeing this issue because your vendor
folder is being included in your _site
folder, which is the “production” folder for your website. Vendor is meant to be read by Jekyll, but is not meant to be shown to the public on your server. If the vendor
folder is included, you are likely to see errors because Jekyll thinks you want the files included in vendor
to be interpreted as production files.
Disclaimer: I am not a developer, and I use Jekyll as an amateur who just appreciates the simplicity of the tool. There are probably more elegant ways to address this error, which involve re-configuring your rbenv or Bundler setup.
However, the simplest way I’ve found to deal with this error is to simply exclude the vendor folder from my Jekyll build, which seems like good practice anyway since I can’t imagine why those files would be needed within the static assets I’m deploying with Netlify, AWS, GitHub Pages, or what have you.
How to fix “invalid date” Jekyll vendor/bundle/ruby issue
The solution is to “exclude” vendor
folder from _site
Inside your config file, search for the “exclude” line. There are a few ways to format it, but it probably looks like this:
Or like this:
Go ahead and exclude vendor like this:
exclude:
- vendor
or:
exclude: ['vendor']
Note that if you have existing “excludes” in your Jekyll project (which is likely if you’re working off a theme you downloaded from somewhere), you need to add the vendor
file to exlude list, not create a new exclude
line within your config file.