Eleventy: Eleventy collections do not implicitly add date field to pages for collections to be sorted by Sortable.js

Created on 18 Oct 2020  路  1Comment  路  Source: 11ty/eleventy

Describe the bug
When I am adding two or more pages to Collections in Eleventy, there is a "Cannot read property 'getTime' of undefined" because there no date field automatically added through the collection which can be used by it inside Sortable.js and hence causing an error.

To Reproduce

  1. Use the below data set for building multiple eleventy pages using any .njk file, add all the pages to the collection through addAllPagesToCollections = true

let data = [
{
name: 'abc'
},
{
name:'xyz'
}
]

Expected behavior
The pages should be built and all the pages can be added to the collection.

Screenshots
image

**"Problem writing Eleventy templates: (more in DEBUG output)

Cannot read property 'getTime' of undefined

TypeError was thrown:
TypeError: Cannot read property 'getTime' of undefined"**
Error file : node_modules\@11ty\eleventy\src\Util\Sortable.js:98:17)

Additional context
If you use the data set below, it works because we can explicitly add a date field and hence the pages can be built and collections can be sorted.

let data = [
{
name: 'abc',
date:'2020-10-07T19:22:49.335Z'
},
{
name:'xyz',
date:'2020-10-07T19:22:49.335Z'
}
]

needs-triage

Most helpful comment

I recently got this error when I was accidentally overriding the page variable provided by eleventy on the pagination:

pagination:
    data: productPages
    size: 1
    alias: page
...
---

Using another name for the pagination alias solves the issue for me.

>All comments

I recently got this error when I was accidentally overriding the page variable provided by eleventy on the pagination:

pagination:
    data: productPages
    size: 1
    alias: page
...
---

Using another name for the pagination alias solves the issue for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michrome picture michrome  路  3Comments

robdodson picture robdodson  路  3Comments

ndaidong picture ndaidong  路  4Comments

proog picture proog  路  3Comments

aaronstezycki picture aaronstezycki  路  3Comments