Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown Liquid filters and variables block build even if strict is off #2229

Closed
xplosionmind opened this issue Feb 18, 2022 · 7 comments
Closed

Comments

@xplosionmind
Copy link

Describe the bug
Even though in my .eleventy.js I have set the following:

  eleventyConfig.setLiquidOptions({
    dynamicPartials: false,
    strictVariables: false,
    strictFilters: false,
    jekyllInclude: true
  });

I continue to get errors of filters not being recognized. As side note, I do not even understand why filters that should be supported by LiquidJS are not recognized.

To Reproduce
Steps to reproduce the behavior:

  1. In an include named stuff.html, write:
{% assign stuff = site.data.stuff | sort: 'current' %}
<section id='stuff' class='row'>
    {% for thing in stuff %}
	<a href='{{ thing.url }}'>{{ thing.title }}</a>
    {% endfor %}
</section>
  1. Place the include inside the file stuff-it.html
  2. Build the website
  3. The error I get is:
Problem writing Eleventy templates: (more in DEBUG output)
> Having trouble rendering html template ./pages/stuff.html

`TemplateContentRenderError` was thrown
> Cannot read properties of undefined (reading 'sort'), file:/Users/tommi/tommi.space/_includes/stuff.html, line:1

`RenderError` was thrown
> Cannot read properties of undefined (reading 'sort')

`TypeError` was thrown:
    TypeError: Cannot read properties of undefined (reading 'sort')
        at sort (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:3306:14)
        at Object.render (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:1914:26)
        at /Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:1807:21
        at Array.reduce (<anonymous>)
        at Object.evalValue$$1 [as evalValue] (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:1806:29)
        at Object.evalValue$$1 [as evalValue] (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:3577:26)
        at Object.render (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:2253:30)
        at Object._callee$ (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:1851:55)
        at tryCatch (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:108:40)
        at Generator.invoke [as _invoke] (/Users/tommi/tommi.space/node_modules/liquidjs/dist/liquid.common.js:319:22)
Wrote 0 files in 0.60 seconds (v0.12.1)

This happens with where_exp, too, as pointed out in #2228

Expected behavior
Liquid filter should be ignored if not recognized. Nevertheless, it should be recognized, too!

Screenshots: n/a

Environment:

  • OS and Version: MacOS 12.2.1
  • Eleventy Version: 1.0.0

Additional context
It would be lovely to get more debugging context for non-developers like I am. I cannot figure out the cause of this not working.

@pdehaan
Copy link
Contributor

pdehaan commented Feb 18, 2022

Seems to work for me. https://github.com/pdehaan/11ty-2229
I suspect it's an issue with your site.data.stuff config, and that is evaluating to undefined which is breaking the LiquidJS sort filter.

Cannot read properties of undefined (reading 'sort')

Here's what my sample /src/_data/site.js file looks like (where site is the name of the file, and data.stuff are nested properties; with stuff being an array so it works with the built-in LiquidJS sort filter):

module.exports = {
  data: {
    stuff: [
      { title: "OnE", url: "/one", current: true },
      { title: "TwO", url: "/two", current: false },
      { title: "ThReE", url: "/three", current: false },
      { title: "FoUr", url: "/four", current: true },
      { title: "FiVe", url: "/five", current: false },
    ],
  },
};

@xplosionmind
Copy link
Author

Still, as pointed out in #2228, also where_exp filter blocks the build… it should be ignored since not recognized, as it is a Jekyll-only filter!

@pdehaan
Copy link
Contributor

pdehaan commented Feb 19, 2022

Sorry, I might be confused here... Not sure where where_exp came from above. It's a Jekyll only filter, sure, but I thought your original comment was about {% assign stuff = site.data.stuff | sort: 'current' %} specifically (where sort is a built-in LiquidJS filter, and seems to be working for me).

If I'm reading the error correctly, Eleventy is saying that LiquidJS is finding the LiquidJS sort filter (and sort is NOT specific to Jekyll), but you're trying to call sort on undefined which is throwing an error. So I'm guessing that your config is wrong and it just isn't finding the value of site.data.stuff in your global _data/ directory.


Aside: Without having tested it, I'd expect where_exp to fail because it isn't a native LiquidJS or Eleventy filter, but I'd guess it'd be ignored if strictVariables: false and/or strictFilters: false was working; but I haven't played with those options very much in LiquidJS since I believe they're relatively new in LiquidJS@9. But those wouldn't apply to the sort since sort is a known filter. (But let's stick to just sort in this issue and leave where_exp in #2228 to avoid too many conversations in a single issue.)

@pdehaan
Copy link
Contributor

pdehaan commented Feb 19, 2022

Created https://github.com/pdehaan/11ty-2228 which seems to successfully ignore the undefined Jekyll where_exp filter (via strictFilters: false config in .eleventy.js).

@xplosionmind
Copy link
Author

As pointed out in #2234, I am getting so confused because it appears that the problem is not only related where_exp or sort filters, but to any Liquid filter in general… I cannot pinpoint the origin of the issue. By cloning your repo to test this issue, everything works.

@AleksandrHovhannisyan
Copy link
Contributor

I think these errors are red herrings. I vaguely recall that when I was migrating my old Jekyll site to 11ty, I got many similar errors about filters not existing. The filters existed, but I think something was breaking in the build pipeline and throwing off the Liquid parser or 11ty.

@xplosionmind
Copy link
Author

As noted in #2234, the problems were not the filters themselves, but rather the nature of the object they were applied to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants