Error: Node not found: KeyName
koitaki opened this issue · 11 comments
Exhausted all thoughts on what could be causing this, and wondering if anyone else has a hint.
My front matter has this:
eleventyNavigation:
key: Alphabet
parent: IPA
I've tested this and it works fine, returning all children, including Alphabet:
{% set breadcrumbs = collections.all | eleventyNavigation("IPA") %}
{{ breadcrumbs | eleventyNavigationToHtml | safe }}
But this breaks & gives me "Error: Node does not exist: Alphabet":
{% set breadcrumbs = collections.all | eleventyNavigationBreadcrumb("Alphabet") %}
{{ breadcrumbs | eleventyNavigationToHtml | safe }}
Sadly its the latter that I'm after, for my breadcrumb navigation.
Thanks in advance if anyone has any useful suggestions or ideas why this could be breaking.
I have the same issue with this which I cannot wrap my head round
I'm trying to generate the breadcrumb trail to the current displayed page which I'm guessing is your exact use case too.
I try to use
---
eleventyNavigation:
key: Chest
parent: Groups
---
{% set navPages = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key) %}
{% for item in navPages %} ...
It keeps telling me that the node bearing the node Chest
is not found even though I'm defining it in the front matter of the same document template which renders the breadcrumb trail
Similar issue for me. I'm trying to generate breadcrumbs for a page generated in a global data file (pulling from an API). I define an eleventyNavigation
object on the data object (with a key
and parent
), and pass the key to eleventyNavigationBreadcrumb
but get a Node does not exist: [Node ID]
where [Node ID]
is the key defined in the eleventyNavigation
object.
Perhaps it's a data cascade issue - the parent page is built from a /content
.md
file. So at the time the page from the global data file is built Node doesn't know about the /content
parent yet?
{% set navPages = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key, { includeSelf: true }) %}
works for me
I also experienced this error and narrowed it down to using the eleventyExcludeFromCollections
option on a page that uses a parent template with breadcrumb-generation code.
I'm preparing a PR to allow the eleventyNavigationBreadcrumb
function to return an empty array if the key it is searching for does not appear in the graph.
I run in the same issue. @noelleleigh could you describe your workaround more in detail, please?
This is what I'm trying:
{% for crumb in crumbs %}
<a class="crumb" href="{{ crumb.url | url }}">{{ crumb.title }}</a>
{% endfor %}```
I run in the same issue. @noelleleigh could you describe your workaround more in detail, please?
This isn't a workaround so much as a patch until my PR is accepted.
Project
Here's a simplified version of my project:
.eleventy.js
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(eleventyNavigationPlugin);
};
_includes/base.njk
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
</head>
<body>
<img src="header.png" alt="My Site">
{% set navPages = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key) %}
{{ navPages | dump | safe }}
{{content | safe}}
</body>
</html>
404.md
---
layout: base.njk
title: Not Found
eleventyExcludeFromCollections: true
eleventyNavigation:
key: "404"
---
Page not found
Error
When building, I get this error:
> % npx @11ty/eleventy 17:22:44
[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] > Having trouble writing template: _site/404/index.html
`TemplateWriterWriteError` was thrown
[11ty] > (./_includes/base.njk)
Error: Node does not exist: 404
`Template render error` was thrown:
[11ty] Template render error: (./_includes/base.njk)
Error: Node does not exist: 404
at Object._prettifyError (/home/noelle/dev/11ty-example/node_modules/nunjucks/src/lib.js:36:11)
at /home/noelle/dev/11ty-example/node_modules/nunjucks/src/environment.js:563:19
at Template.root [as rootRenderFunc] (eval at _compile (/home/noelle/dev/11ty-example/node_modules/nunjucks/src/environment.js:633:18), <anonymous>:33:3)
at Template.render (/home/noelle/dev/11ty-example/node_modules/nunjucks/src/environment.js:552:10)
at /home/noelle/dev/11ty-example/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:484:14
at new Promise (<anonymous>)
at /home/noelle/dev/11ty-example/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:483:14
at TemplateLayout.render (/home/noelle/dev/11ty-example/node_modules/@11ty/eleventy/src/TemplateLayout.js:160:31)
at async Template.renderPageEntry (/home/noelle/dev/11ty-example/node_modules/@11ty/eleventy/src/Template.js:842:17)
at async /home/noelle/dev/11ty-example/node_modules/@11ty/eleventy/src/Template.js:872:21
[11ty] Wrote 0 files in 0.12 seconds (v1.0.0)
This is caused by this code for the eleventyNavigationBreadcrumb
template filter:
eleventy-navigation/eleventy-navigation.js
Lines 49 to 54 in 18cfb4d
When graph.dependenciesOf(activeKey)
is called, an exception is thrown because activeKey
does not appear in graph
(because we excluded it using eleventyExcludeFromCollections
). We still want to use base.njk
layout for the 404 page because it contains a header image we need for branding, but since the 404 page doesn't appear in collections, it cannot appear in the navigation graph.
Fix
My workaround was to fork eleventy-navigation and add an option to eleventyNavigationBreadcrumb
which will tell the function to return an empty list if activeKey
doesn't appear in the graph, which means no breadcrumbs will be rendered.
Change in forked plugin code:
diff --git a/eleventy-navigation.js b/eleventy-navigation.js
index 7d0637c..46ffc0a 100644
--- a/eleventy-navigation.js
+++ b/eleventy-navigation.js
@@ -48,6 +48,10 @@ function getDependencyGraph(nodes) {
function findBreadcrumbEntries(nodes, activeKey, options = {}) {
let graph = getDependencyGraph(nodes);
+ if (options.handleMissing && !graph.hasNode(activeKey)) {
+ // Fail gracefully if the key isn't in the graph
+ return [];
+ }
let deps = graph.dependenciesOf(activeKey);
if(options.includeSelf) {
deps.push(activeKey);
Then I replaced eleventy-navigation
in my package.json with my forked version, and made this change to my base template
<body>
<img src="header.png" alt="My Site">
- {% set navPages = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key) %}
+ {% set navPages = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key, {handleMissing: true}) %}
{{ navPages | dump | safe }}
{{content | safe}}
</body>
Thanks for this thread, for casual viewers, note that the released key name in 3.3+ is: 'allowMissing' (not 'handleMissing')
Error Output
[11ty] Problem writing Eleventy templates:
[11ty] 1. Having trouble rendering njk template ./_src/components/breadcrumb.njk (via TemplateContentRenderError)
Eleventy:EleventyErrorHandler (error stack): TemplateContentRenderError: Having trouble rendering njk template ./_src/components/breadcrumb.njk
Eleventy:EleventyErrorHandler at Template._render (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/TemplateContent.js:455:15)
Eleventy:EleventyErrorHandler at processTicksAndRejections (node:internal/process/task_queues:96:5)
Eleventy:EleventyErrorHandler at async Template.getTemplateMapContent (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/Template.js:1077:19)
Eleventy:EleventyErrorHandler at async TemplateMap.populateContentDataInMap (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/TemplateMap.js:461:39)
Eleventy:EleventyErrorHandler at async TemplateMap.cache (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/TemplateMap.js:360:5)
Eleventy:EleventyErrorHandler at async TemplateWriter._createTemplateMap (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/TemplateWriter.js:244:5)
Eleventy:EleventyErrorHandler at async TemplateWriter.generateTemplates (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/TemplateWriter.js:277:5)
Eleventy:EleventyErrorHandler at async TemplateWriter.write (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/TemplateWriter.js:323:23)
Eleventy:EleventyErrorHandler at async Eleventy.executeBuild (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/Eleventy.js:1003:13) +0ms
[11ty] 2. (./_src/components/breadcrumb.njk)
[11ty] Error: filter not found: eleventyNavigationBreadcrumb (via Template render error)
Eleventy:EleventyErrorHandler (error stack): Template render error: (./_src/components/breadcrumb.njk)
Eleventy:EleventyErrorHandler Error: filter not found: eleventyNavigationBreadcrumb
Eleventy:EleventyErrorHandler at Object._prettifyError (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/nunjucks/src/lib.js:36:11)
Eleventy:EleventyErrorHandler at /home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/nunjucks/src/environment.js:563:19
Eleventy:EleventyErrorHandler at Template.root [as rootRenderFunc] (eval at _compile (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/nunjucks/src/environment.js:633:18), <anonymous>:60:3)
Eleventy:EleventyErrorHandler at Template.render (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/nunjucks/src/environment.js:552:10)
Eleventy:EleventyErrorHandler at /home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:485:14
Eleventy:EleventyErrorHandler at new Promise (<anonymous>)
Eleventy:EleventyErrorHandler at /home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:484:14
Eleventy:EleventyErrorHandler at Template._render (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/TemplateContent.js:432:28)
Eleventy:EleventyErrorHandler at processTicksAndRejections (node:internal/process/task_queues:96:5)
Eleventy:EleventyErrorHandler at async Template.getTemplateMapContent (/home/denverpr/nodevenv/repositories/yada-11ty-bootstrap-theme/16/lib/node_modules/@11ty/eleventy/src/Template.js:1077:19) +0ms
Template File
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
{% set navPages = collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key, {handleMissing: true}) %}
{% for crumb in navPages %}
<li class="breadcrumb-item{% if crumb.url == page.url %} active" aria-current="page">{{ crumb.title }}{% endif %}>{% else %}<a class="pretty-link" href="{{ crumb.url | url }}">{{ crumb.title }}</a>
{%- endfor %}
</ol>
</nav>
Question
What or where should I look?
@inetbiz Sounds like you might have forgot to addPlugin
this one? https://www.11ty.dev/docs/plugins/navigation/#installation
(next time please file a new issue so folks don’t get emails on these old issues!)
Hi, thank you for this fix. I encountered the issue, which was indeed fixed by the allowMissing flag ;)
In my case, it turned out that my page hierarchy was wrong. On the top of the navigation tree, I had a reference to a non existing parent, which caused the error. Because of it, all pages in the faulty branch are missing the breadcrumbs. Additional symptom is the this branch did not appear in the content generated by the eleventyNavigationToHtml filter neither.
Hope this helps