11ty / eleventy

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

Cannot JSON.stringify collections.all #2947

Open kaceo opened 1 year ago

kaceo commented 1 year ago

Operating system

debian 11

Eleventy

2.0.1

Describe the bug

The template described in https://www.11ty.dev/docs/permalinks/#custom-file-formats does not work.

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble rendering ejs template ./tpages/index.ejs (via TemplateContentRenderError)
[11ty] 2. ./tpages/index.ejs:2
[11ty]     1|
[11ty]  >> 2| <%- JSON.stringify(collections.all) -%>
[11ty]     3|
[11ty]     4|
[11ty]
[11ty] Converting circular structure to JSON
[11ty]     --> starting at object with constructor 'Object'
[11ty]     |     property 'doctype' -> object with constructor 'Object'
[11ty]     |     property 'inside' -> object with constructor 'Object'
[11ty]     |     property 'internal-subset' -> object with constructor 'Object'
[11ty]     --- property 'inside' closes the circle (via TypeError)
[11ty]
[11ty] Original error stack trace: TypeError: ./tpages/index.ejs:2
[11ty]     1|
[11ty]  >> 2| <%- JSON.stringify(collections.all) -%>
[11ty]     3|
[11ty]     4|
[11ty]
[11ty] Converting circular structure to JSON
[11ty]     --> starting at object with constructor 'Object'
[11ty]     |     property 'doctype' -> object with constructor 'Object'
[11ty]     |     property 'inside' -> object with constructor 'Object'
[11ty]     |     property 'internal-subset' -> object with constructor 'Object'
[11ty]     --- property 'inside' closes the circle

Reproduction steps

Create an empty project with this file index.ejs

---
permalink: "index.json"
---
<%- JSON.stringify(collections.all) -%>

as stated in https://www.11ty.dev/docs/permalinks/#custom-file-formats

Expected behavior

Expect to create a file index.json with the content of all pages.

Reproduction URL

No response

Screenshots

No response

pdehaan commented 1 year ago

It might work if you exclude the page from the collections using something like eleventyExcludeFromCollections: true in the front matter.

Otherwise I generally use Node's util.inspect() for debugging which handles circular JSON, but not sure how that works w/ EJS templating.