Issue with Github actions
Closed this issue · 9 comments
Thanks to your previous help I got the ogImage working locally, but when I pushed the changes to git, a github action runs and compiles everything and then copies the results over to my server. When this process happened with the ogImage content, it threw an error. Is it related to it not being able to find the template?
[11ty] 1. Having trouble writing to "html/books/index.html" from "./src/books/books.11ty.js" (via EleventyTemplateError)
[11ty] 2. (./src/_includes/books.njk)
[11ty] Template render error: (/github/workspace/src/_includes/header-books.njk)
[11ty] EleventyShortcodeError: Error with Nunjucks shortcode `ogImage` (via Template render error)
[11ty] 3. Cannot read properties of undefined (reading 'includes') (via Template render error)
[11ty]
[11ty] Original error stack trace: TypeError: Cannot read properties of undefined (reading 'includes')
[11ty] at new TemplateRender (/github/workspace/node_modules/@11ty/eleventy/src/TemplateRender.js:29:73)
[11ty] at compileFile (/github/workspace/node_modules/@11ty/eleventy/src/Plugins/RenderPlugin.js:66:12)
[11ty] at renderOgImage (/github/workspace/node_modules/eleventy-plugin-og-image/src/renderOgImage.js:24:31)
[11ty] at Object.ogImage (/github/workspace/node_modules/eleventy-plugin-og-image/.eleventy.js:56:40)
[11ty] at Object.<anonymous> (/usr/local/lib/node_modules/@11ty/eleventy/src/BenchmarkGroup.js:32:26)
[11ty] at ShortcodeFunction.run (/usr/local/lib/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:200:14)
[11ty] at Template.root [as rootRenderFunc] (eval at _compile (/usr/local/lib/node_modules/@11ty/eleventy/node_modules/nunjucks/src/environment.js:527:18), <anonymous>:12:35)
[11ty] at Template.render (/usr/local/lib/node_modules/@11ty/eleventy/node_modules/nunjucks/src/environment.js:454:10)
[11ty] at eval (eval at _compile (/usr/local/lib/node_modules/@11ty/eleventy/node_modules/nunjucks/src/environment.js:527:18), <anonymous>:18:10)
[11ty] at fn (/usr/local/lib/node_modules/@11ty/eleventy/node_modules/a-sync-waterfall/index.js:26:24)
Hard to tell without seeing more of the project. Is it public on GitHub?
I have made the repo public, thank you so much for your help with this.
https://github.com/phoopee3/blog
In the src/_includes
folde are the layouts for the site, there is the books.njk
layout which calls the header-books.njk
header that has the reference to ogImage
in it. ogImage
uses the template file in the same directory, named og-book.og.njk
.
Again, this worked successfully locally, but not with the github action build.
Will have a look later today! Did it work locally with the build
command or only serve
?
That's a great question, I only tried it with serve, I will try it with build locally and see what happens.
Yes, the build locally worked successfully.
I tried moving the template to a different folder, so it's now in src/og-templates
instead of _includes
, but it's the same error during the build on github actions
I've checked out your project and it also builds successfully on my machine. I think there are multiple problems in your GitHub actions setup and there might be a differnent 11ty version installed on CI than locally. First, please run npm install
locally and commit the package-lock.json
, I see a lot of changes when installing locally. I would recommend against using the eleventy action as it hasn't been updated in two years. A simple action would be:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm run build
I will try this all and I appreciate your assistance!
I was able to get it working, you are fantastic!