11ty / eleventy

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

"Expecting a TemplateConfig instance" when using Liquid in Markdown frontmatter #2933

Closed scinos closed 1 year ago

scinos commented 1 year ago

Operating system

macOS 12.6

Eleventy

2.0.1

Describe the bug

I get these errors:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble rendering md template ./src/tags.md (via TemplateContentRenderError)
[11ty] 2. Having trouble compiling template ./src/tags.md (via TemplateContentCompileError)
[11ty] 3. Expecting a TemplateConfig instance. (via Error)

The template that throws those errors is:

---
pagination:
  data: collections.tags
  size: 1
  alias: tag
permalink: 'tags/{{ tag | slugify }}/index.html'
eleventyComputed:
  title: 'Posts - {{ tag }}'
layout: 'pages/tag.jsx'
---

This was working with Eleventy 2.0.0, it started to fail after the update to 2.0.1.

The relevant part of the DEBUG logs is:

  Eleventy:TemplateConfig Current configuration: { pathPrefix: '/', markdownTemplateEngine: 'liquid', htmlTemplateEngine: 'liquid', htmlOutputSuffix: '-o', dataFileSuffixes: [ '.11tydata', '' ], dataFileDirBaseNameOverride: false, keys: { package: 'pkg', layout: 'layout', permalink: 'permalink', permalinkRoot: 'permalinkBypassOutputDir', engineOverride: 'templateEngineOverride', computed: 'eleventyComputed' }, dir: { input: 'src', includes: '_includes', data: '_data', output: '_site' }, handlebarsHelpers: { slug: [Function (anonymous)], slugify: [Function (anonymous)], url: [Function (anonymous)], log: [Function (anonymous)], serverlessUrl: [Function (anonymous)], getCollectionItemIndex: [Function (anonymous)], getCollectionItem: [Function (anonymous)], getPreviousCollectionItem: [Function (anonymous)], getNextCollectionItem: [Function (anonymous)], cssmin: [Function (anonymous)], eleventyNavigation: [Function (anonymous)], eleventyNavigationBreadcrumb: [Function (anonymous)], eleventyNavigationToHtml: [Function (anonymous)], eleventyNavigationToMarkdown: [Function (anonymous)] }, nunjucksFilters: { slug: [Function (anonymous)], slugify: [Function (anonymous)], url: [Function (anonymous)], log: [Function (anonymous)], serverlessUrl: [Function (anonymous)], getCollectionItemIndex: [Function (anonymous)], getCollectionItem: [Function (anonymous)], getPreviousCollectionItem: [Function (anonymous)], getNextCollectionItem: [Function (anonymous)], cssmin: [Function (anonymous)], eleventyNavigation: [Function (anonymous)], eleventyNavigationBreadcrumb: [Function (anonymous)], eleventyNavigationToHtml: [Function (anonymous)], eleventyNavigationToMarkdown: [Function (anonymous)] }, passthroughFileCopy: true, templateFormats: [ 'liquid',   'ejs', 'md',       'hbs', 'mustache', 'haml', 'pug',      'njk', 'html',     '11ty.js', 'jsx' ], transforms: {}, linters: {}, globalData: {}, layoutAliases: {}, layoutResolution: true, passthroughCopies: { 'src/img': { outputPath: true, copyOptions: {} } }, liquidOptions: {}, liquidTags: {}, liquidFilters: { slug: [Function (anonymous)], slugify: [Function (anonymous)], url: [Function (anonymous)], log: [Function (anonymous)], serverlessUrl: [Function (anonymous)], getCollectionItemIndex: [Function (anonymous)], getCollectionItem: [Function (anonymous)], getPreviousCollectionItem: [Function (anonymous)], getNextCollectionItem: [Function (anonymous)], cssmin: [Function (anonymous)], eleventyNavigation: [Function (anonymous)], eleventyNavigationBreadcrumb: [Function (anonymous)], eleventyNavigationToHtml: [Function (anonymous)], eleventyNavigationToMarkdown: [Function (anonymous)] }, liquidShortcodes: {}, liquidPairedShortcodes: {}, nunjucksEnvironmentOptions: {}, nunjucksPrecompiledTemplates: {}, nunjucksAsyncFilters: {}, nunjucksTags: {}, nunjucksGlobals: {}, nunjucksAsyncShortcodes: {}, nunjucksShortcodes: {}, nunjucksAsyncPairedShortcodes: {}, nunjucksPairedShortcodes: {}, handlebarsShortcodes: {}, handlebarsPairedShortcodes: {}, javascriptFunctions: { slug: [Function (anonymous)], slugify: [Function (anonymous)], url: [Function (anonymous)], log: [Function (anonymous)], serverlessUrl: [Function (anonymous)], getCollectionItemIndex: [Function (anonymous)], getCollectionItem: [Function (anonymous)], getPreviousCollectionItem: [Function (anonymous)], getNextCollectionItem: [Function (anonymous)], cssmin: [Function (anonymous)], eleventyNavigation: [Function (anonymous)], eleventyNavigationBreadcrumb: [Function (anonymous)], eleventyNavigationToHtml: [Function (anonymous)], eleventyNavigationToMarkdown: [Function (anonymous)] }, pugOptions: {}, ejsOptions: {}, markdownHighlighter: null, libraryOverrides: { md: MarkdownIt { inline: [ParserInline], block: [ParserBlock], core: [Core], renderer: [Renderer], linkify: [LinkifyIt], validateLink: [Function: validateLink], normalizeLink: [Function: normalizeLink], normalizeLinkText: [Function: normalizeLinkText], utils: [Object], helpers: [Object], options: [Object] } }, dynamicPermalinks: true, useGitIgnore: true, ignores: Set(2) { '**/node_modules/**', '.git/**' }, watchIgnores: Set(2) { '**/node_modules/**', '.git/**' }, dataDeepMerge: true, watchJavaScriptDependencies: true, additionalWatchTargets: [ 'src/css' ], serverOptions: {}, chokidarConfig: {}, watchThrottleWaitTime: 0, frontMatterParsingOptions: undefined, dataExtensions: Map(0) {}, extensionMap: Set(1) { { key: 'jsx', extension: 'jsx', init: [AsyncFunction: init], getData: true, getInstanceFromInputPath: [Function: getInstanceFromInputPath], read: false, compile: [AsyncFunction: compile], compileOptions: [Object] } }, quietMode: false, events: AsyncEventEmitter { _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined, [Symbol(kCapture)]: false }, benchmarkManager: BenchmarkManager { benchmarkGroups: { Configuration: [BenchmarkGroup], Aggregate: [BenchmarkGroup] }, isVerbose: true, start: 120.63566589355469 }, plugins: [ { plugin: [Function], options: undefined, pluginNamespace: '' }, { plugin: [Function (anonymous)], options: [Object], pluginNamespace: '' } ], useTemplateCache: true, precompiledCollections: {}, dataFilterSelectors: Set(0) {}, libraryAmendments: {}, serverPassthroughCopyBehavior: 'copy', urlTransforms: [] } +0ms
...
  Eleventy:TemplateContent Having trouble compiling template ./src/tags.md: 'tags/{{ tag | slugify }}/index.html' +0ms
  Eleventy:TemplateContent Having trouble rendering md template ./src/tags.md: 'tags/{{ tag | slugify }}/index.html' +1ms
[11ty] Problem writing Eleventy templates:
[11ty] 1. Having trouble rendering md template ./src/tags.md (via TemplateContentRenderError)
  Eleventy:EleventyErrorHandler (error stack): TemplateContentRenderError: Having trouble rendering md template ./src/tags.md
  Eleventy:EleventyErrorHandler     at Template._render (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateContent.js:531:15)
  Eleventy:EleventyErrorHandler     at Template._getLink (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Template.js:251:24)
  Eleventy:EleventyErrorHandler     at Template.getOutputLocations (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Template.js:301:16)
  Eleventy:EleventyErrorHandler     at Pagination.getPageTemplates (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Plugins/Pagination.js:419:51)
  Eleventy:EleventyErrorHandler     at Template.getTemplates (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Template.js:705:27)
  Eleventy:EleventyErrorHandler     at TemplateMap.initDependencyMap (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateMap.js:414:22)
  Eleventy:EleventyErrorHandler     at TemplateMap.cache (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateMap.js:459:5)
  Eleventy:EleventyErrorHandler     at TemplateWriter._createTemplateMap (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:330:5)
  Eleventy:EleventyErrorHandler     at TemplateWriter.generateTemplates (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:360:5)
  Eleventy:EleventyErrorHandler     at TemplateWriter.write (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:407:23) +0ms
[11ty] 2. Having trouble compiling template ./src/tags.md (via TemplateContentCompileError)
  Eleventy:EleventyErrorHandler (error stack): TemplateContentCompileError: Having trouble compiling template ./src/tags.md
  Eleventy:EleventyErrorHandler     at Template.compile (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateContent.js:376:13)
  Eleventy:EleventyErrorHandler     at Template._render (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateContent.js:486:16)
  Eleventy:EleventyErrorHandler     at Template._getLink (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Template.js:251:24)
  Eleventy:EleventyErrorHandler     at Template.getOutputLocations (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Template.js:301:16)
  Eleventy:EleventyErrorHandler     at Pagination.getPageTemplates (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Plugins/Pagination.js:419:51)
  Eleventy:EleventyErrorHandler     at Template.getTemplates (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Template.js:705:27)
  Eleventy:EleventyErrorHandler     at TemplateMap.initDependencyMap (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateMap.js:414:22)
  Eleventy:EleventyErrorHandler     at TemplateMap.cache (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateMap.js:459:5)
  Eleventy:EleventyErrorHandler     at TemplateWriter._createTemplateMap (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:330:5)
  Eleventy:EleventyErrorHandler     at TemplateWriter.generateTemplates (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:360:5) +0ms
[11ty] 3. Expecting a TemplateConfig instance. (via Error)
  Eleventy:EleventyErrorHandler (error stack): Error: Expecting a TemplateConfig instance.
  Eleventy:EleventyErrorHandler     at Liquid.get config [as config] (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Engines/TemplateEngine.js:40:11)
  Eleventy:EleventyErrorHandler     at new Liquid (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Engines/Liquid.js:20:31)
  Eleventy:EleventyErrorHandler     at TemplateEngineManager.getEngine (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateEngineManager.js:124:20)
  Eleventy:EleventyErrorHandler     at Markdown.compile (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/Engines/Markdown.js:59:37)
  Eleventy:EleventyErrorHandler     at TemplateRender.getCompiledTemplate (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateRender.js:269:26)
  Eleventy:EleventyErrorHandler     at Template.compile (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateContent.js:362:42)
  Eleventy:EleventyErrorHandler     at Template._render (/Users/sergio/src/blogs/scinos-blog-11ty/node_modules/@11ty/eleventy/src/TemplateContent.js:486:16) +1ms

Reproduction URL

https://github.com/scinos/scinos-blog-11ty/pull/25

Checkout, run yarn && yarn build.

Screenshots

No response

pdehaan commented 1 year ago

Hhmm, I'm a bit lost. I can reproduce the issue with your repo if I downgrade from 2.0.1 to 2.0.0. I managed to "fix" the error, but it required me disabling the eleventy-plugin-react-ssr plugin. So it might be related to that plugin+JSX, although odd that it worked in 2.0.0 and broke in a patch release. But it's also possible there's an incompatibility with the plugin and something in 2.0.1 changes. Not sure if you can try a different JSX engine plugin, but https://www.npmjs.com/package/eleventy-plugin-jsx looks pretty stale. Looking at https://www.11ty.dev/docs/plugins/ it seems like your react-ssr plugin was the only one mentioning "react" though.

scinos commented 1 year ago

You are right, it was eleventy-plugin-react-ssr 🤦🏼 . Fixed in 1.0.3 in case anybody else is interested.

What I still don't get is why this was working with Eleventy 2.0.0. I'm very positive it worked, because I have an online blog with eleventy 2.0.0 + eleventy-plugin-react-ssr. Given this was related to reseting request cache, maybe it is not deterministic? I don't know.

Anyway, thanks for your help @pdehaan. This is fixed now.