11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.57k stars 481 forks source link

Cannot read properties of undefined (reading 'filter') #3333

Closed groenroos closed 2 days ago

groenroos commented 1 week ago

Operating system

macOS Sonoma 14.4.1

Eleventy

3.0.0-alpha.13

Describe the bug

When trying to build a project which works fine in Eleventy 2.0.1, using Eleventy 3.0.0-alpha.13, the build fails with the following error:

[11ty] Cannot read properties of undefined (reading 'filter') (via TypeError)
[11ty]
[11ty] Original error stack trace: TypeError: Cannot read properties of undefined (reading 'filter')
[11ty]     at TemplateData.getIncludedTagNames (file://node_modules/@11ty/eleventy/src/Data/TemplateData.js:703:22)
[11ty]     at file://node_modules/@11ty/eleventy/src/TemplateCollection.js:64:33
[11ty]     at Array.filter (<anonymous>)
[11ty]     at TemplateCollection.getFilteredByTag (file://node_modules/@11ty/eleventy/src/TemplateCollection.js:63:30)
[11ty]     at TemplateMap.getTaggedCollection (file://node_modules/@11ty/eleventy/src/TemplateMap.js:613:29)
[11ty]     at TemplateMap.setCollectionByTagName (file://node_modules/@11ty/eleventy/src/TemplateMap.js:379:41)
[11ty]     at TemplateMap.initDependencyMap (file://node_modules/@11ty/eleventy/src/TemplateMap.js:401:16)
[11ty]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[11ty]     at async TemplateMap.cache (file://node_modules/@11ty/eleventy/src/TemplateMap.js:444:3)
[11ty]     at async TemplateWriter._createTemplateMap (file://node_modules/@11ty/eleventy/src/TemplateWriter.js:319:3)

As there's no pointer to a particular project template or file, it's hard to work out what content is causing this to happen, or how to create a minimal reproduction. The DEBUG mode doesn't appear to output anything that jumps out at me, but happy to provide additional details.

The error seems to relate to the tags data not being an array, as expected by the TemplateData.getIncludedTagNames method. The site content does often define tags as a single string (instead of an array), in templates of both Liquid and Markdown, as well as via data files. This has previously been abstracted away by Eleventy 2.x.

Reproduction steps

  1. Unknown aspect of content, potentially related to tags being defined as a string and not an array
  2. Upgrade project to Eleventy 3
  3. Build

Expected behavior

The project should build without errors, without having to change all previous content.

Reproduction URL

No response

Screenshots

No response

zachleat commented 1 week ago

tags should still be normalized to Array from String in 3.0 too.

I did do a small cleanup of this section of the code for 3.0.0-alpha.14 released today—can you test again before we deep dive in?

https://github.com/11ty/eleventy/commit/fa0b636a17f50a43d1fa5945c003f1bde4e9f4c0

I can have a look at a more complex test case too, if that helps.

groenroos commented 2 days ago

Upgrading to 3.0.0-alpha.14 seems to have replaced this error with a different one, so I can only assume that this was addressed in alpha.14. Thank you!