Open
Description
The build process sometimes ends with an exception TemplateContentPrematureUseError
.
Steps to reproduce
Steps to reproduce the behavior:
- I have a bunch of posts in several collection
- For one specific collection, I want to generate a RSS feed, placing it under
/_site/tango/rss/index.njk
- The RSS feed looks like this:
---js
{
permalink: "tango/rss/index.xml",
excludeFromSitemap: true,
pubDate: new Date()
}
---
<?xml version="1.0" encoding="UTF-8"?>
[... snip]
{% for item in collections.tango %}
<item>
[... snip]
<content:encoded>
<![CDATA[{{ item.templateContent | htmlToAbsoluteUrls(absolutePostUrl) | safe }}]]>
</content:encoded>
</item>
{% endfor %}
[... snip]
The build script invokes .\node_modules\.bin\eleventy.cmd --output=./build
. This comes out on the command line:
[... snip]
Unhandled rejection in promise ([object Promise]): (more in DEBUG output)
> Tried to use templateContent too early (./_site/tango/2020-12-26-review-para-siempre-by-pablo-valle-sexteto.md)
`TemplateContentPrematureUseError` was thrown:
TemplateContentPrematureUseError: Tried to use templateContent too early (./_site/tango/2020-12-26-review-para-siempre-by-pablo-valle-sexteto.md)
at Object.get templateContent [as templateContent] (C:\Users\tomas\Documents\Projects\Blog\node_modules\@11ty\eleventy\src\Template.js:484:19)
at Object.memberLookup (C:\Users\tomas\Documents\Projects\Blog\node_modules\nunjucks\src\runtime.js:253:17)
at eval (eval at _compile (C:\Users\tomas\Documents\Projects\Blog\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:85:59)
at iterCallback (C:\Users\tomas\Documents\Projects\Blog\node_modules\nunjucks\src\runtime.js:295:11)
at next (C:\Users\tomas\Documents\Projects\Blog\node_modules\nunjucks\src\lib.js:326:7)
at eval (eval at _compile (C:\Users\tomas\Documents\Projects\Blog\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:89:1)
at C:\Users\tomas\Documents\Projects\Blog\node_modules\@11ty\eleventy-plugin-rss\.eleventy.js:21:7
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
The first item in the stack trace (in which post this error occurs) changes from time to time. And sometimes, there is no error and everything works as expected.
When I remove this line from /_site/tango/rss/index.njk
, there is no error:
<![CDATA[{{ item.templateContent | htmlToAbsoluteUrls(absolutePostUrl) | safe }}]]>
Expected behavior
The build process finishes normally
Environment:
- OS and Version: Windows 10, tested also under WSL 2 in Ubuntu 20.04 (files on the Windows filesystem), the problem appears also on a Linux machine running Ubuntu 20.04
- Eleventy version
0.11.1