question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can't use eleventy-img plugin in component

See original GitHub issue
  • no error when used outside component
  • no error with hard-coded src and alt

Looks like the shortcode/plugin isn’t able t use the default values from the .toml file.

toml:

[component]
structures = []
label = "hero-base"
description = ""
icon = ""
tags = []

[props]
description = "Lorem ipsum dolor sit amet consectetur adipisicing elit. Alias mollitia ducimus facere?"

[props.title]
small = "Mijn mooie"
big = "grote titel"

[props.afbeelding]
image = "/assets/img/index-hero.jpg"
alt ="mijn alt"

liquid:

<section class="hero-base">
  {% image afbeelding.image, afbeelding.alt, "hero-base__img", "100vw", "600, 900, 1200, 1400, 1800" %}
  <div x-ref="content" class="hero-base__content">
    {% bookshop "title"  bind: title %}
    <p class="hero-base__p">{{ description }}</p>
  </div>
</section> 
Problem writing Eleventy templates: (more in DEBUG output)
> Having trouble rendering liquid template ./component-library/components/hero/base/base.eleventy.liquid

`TemplateContentRenderError` was thrown
> ENOENT: no such file or directory, stat '.undefined', file:./component-library/components/hero/base/base.eleventy.liquid, line:2

`RenderError` was thrown
> ENOENT: no such file or directory, stat '.undefined'

`Error` was thrown:
    Error: ENOENT: no such file or directory, stat '.undefined'
        at Object.statSync (node:fs:1536:3)
        at Image.getInMemoryCacheKey (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\@11ty\eleventy-img\img.js:139:32)
        at queueImage (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\@11ty\eleventy-img\img.js:565:15)
        at Object.imageShortcode (C:\Users\silve\11ty\vda-bouwmaterialen\.eleventy.js:16:24)
        at Object.<anonymous> (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\@11ty\eleventy\src\BenchmarkGroup.js:30:26)
        at Object.render (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\@11ty\eleventy\src\Engines\Liquid.js:147:25)
        at Object._callee$ (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\liquidjs\dist\liquid.common.js:1851:55)
        at tryCatch (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\liquidjs\dist\liquid.common.js:108:40)
        at Generator.invoke [as _invoke] (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\liquidjs\dist\liquid.common.js:319:22)
        at Generator.prototype.<computed> [as next] (C:\Users\silve\11ty\vda-bouwmaterialen\node_modules\liquidjs\dist\liquid.common.js:156:21)
Copied 26 files / Wrote 0 files in 0.27 seconds (v0.12.1)
Watching…
�📚 New components — no connected client
[Browsersync] Reloading Browsers...

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bglwcommented, Jun 17, 2022

Hi @silveltman 👋

Wee update here. Plugins are still inaccessible from Bookshop components, but we do have a new feature where you can detect the environment from your template and render different content. You can see some docs on that here: Rendering Different Content When Live Editing

In this case, that would let you do something like the following:

{% if env_bookshop_live %}
  <img x-ref="img" src="{{ afbeelding.image }}" alt="{{ afbeelding.alt }}" class="hero-base__img">
{% else %}
  {% image afbeelding.image, afbeelding.alt, "hero-base__img", "100vw", "600, 900, 1200, 1400, 1800" %}
{% endif %}

You would still have a slight rendering difference between the component browser and the live site, but being aware of that might be enough.

Let me know your thoughts!

0reactions
bglwcommented, Apr 6, 2022

Hi @silveltman,

Apologies for the slow reply. You are correct that plugins are currently unsupported from within Bookshop components — the in-browser rendering doesn’t use Eleventy directly so doesn’t have access to any plugins you have defined there.

There is an undocumented way to add your own plugins to Bookshop’s live editing environment, but it would require writing a new JavaScript file that implemented the behavior you’re after. We sometimes use this for re-implementing a simple string transformation plugin.

In this case, I can’t see a way that eleventy-img could be made to work in the browser, but you could add a plugin that performs some fallback behavior to prevent an error when Bookshop is rendering the component.

Let me know if this is something you’re keen on and I’ll write up a quick documentation section on adding these plugins 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eleventy-img plugin template render error: ENOENT: no such ...
Trying the eleventy-img plugin for the first time in a hitherto working 11ty dev site. Docs look good, but the devil if I...
Read more >
Image — Eleventy
Low level utility to perform build-time image transformations for both vector and raster images. Output multiple sizes, save multiple formats, cache remote ...
Read more >
Using Eleventy's official image plugin | BryceWray.com
First, let's install Eleventy Image in your Eleventy project. Install the plugin package. In your chosen OS's terminal interface, enter the ...
Read more >
Optimizing Images with the 11ty Image Plugin
Fortunately, Eleventy offers a better alternative: the official eleventy-image plugin, which can be used to resize and transform both local ...
Read more >
Don't Shut Down Your Business! Instead Use Eleventy Image
Are your JavaScripts making too much noise all the time? Well image optimization can't solve that problem but I am here to tell...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found