eleventy
eleventy copied to clipboard
Missing layout error should report the problem template file
When there is an error writing templates, it would be helpful to print the affected file.
I got this error 'You’re trying to use a layout that does not exist' and the missing template name, but it didn't print the file it was trying to render (that I could see).
Eleventy:EleventyErrorHandler Problem writing Eleventy templates: +0ms
Eleventy:EleventyErrorHandler You’re trying to use a layout that does not exist: default (undefined)
Eleventy:EleventyErrorHandler
Eleventy:EleventyErrorHandler `Error` was thrown: +1ms
Eleventy:EleventyErrorHandler (error stack): Error: You’re trying to use a layout that does not exist: default (undefined)
Eleventy:EleventyErrorHandler at TemplateLayoutPathResolver.getFullPath (/tmp/page/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:84:13)
Eleventy:EleventyErrorHandler at new TemplateLayout (/tmp/page/node_modules/@11ty/eleventy/src/TemplateLayout.js:18:7)
Eleventy:EleventyErrorHandler at Function.getTemplate (/tmp/page/node_modules/@11ty/eleventy/src/TemplateLayout.js:38:16)
Eleventy:EleventyErrorHandler at Template.getData (/tmp/page/node_modules/@11ty/eleventy/src/Template.js:218:37) +0ms
Could you provide a minimal working example? (I can imagine something, but having code eases the investigation)
@Ryuno-Ki sure!
Editing the layout
field on a post in eleventy-base-blog will do it. Example commit
You can run npm run build
on Glitch here: https://glitch.com/edit/console.html?psimyn-eleventy-issue-727
Or check locally:
git clone --depth 1 --branch repro-727 https://github.com/psimyn/eleventy-base-blog.git repro-727
cd repro-727
npm install
npm run build
Output (summary)
Problem writing Eleventy templates: (more in DEBUG output)
> You’re trying to use a layout that does not exist: default (undefined)
`Error` was thrown:
Error: You’re trying to use a layout that does not exist: default (undefined)
Preferred output could look like:
`Error` was thrown (in posts/firstpost.md):
Error: You’re trying to use a layout that does not exist: default (undefined)
Confirmed this as still valid.
[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] You’re trying to use a layout that does not exist: flsdjkfj (undefined) (via Error)
[11ty]
[11ty] Original error stack trace: Error: You’re trying to use a layout that does not exist: flsdjkfj (undefined)
[11ty] at TemplateLayoutPathResolver.getFullPath (/Users/zachleat/Code/eleventy/src/TemplateLayoutPathResolver.js:95:13)
[11ty] at new TemplateLayout (/Users/zachleat/Code/eleventy/src/TemplateLayout.js:22:7)
[11ty] at Function.getTemplate (/Users/zachleat/Code/eleventy/src/TemplateLayout.js:47:18)
[11ty] at Template.getLayout (/Users/zachleat/Code/eleventy/src/Template.js:125:37)
[11ty] at Template.getData (/Users/zachleat/Code/eleventy/src/Template.js:375:25)
[11ty] at async TemplateMap.add (/Users/zachleat/Code/eleventy/src/TemplateMap.js:60:16)
[11ty] at async Promise.all (index 0)
[11ty] at async TemplateWriter._createTemplateMap (/Users/zachleat/Code/eleventy/src/TemplateWriter.js:243:5)
[11ty] at async TemplateWriter.generateTemplates (/Users/zachleat/Code/eleventy/src/TemplateWriter.js:277:5)
[11ty] at async TemplateWriter.write (/Users/zachleat/Code/eleventy/src/TemplateWriter.js:324:23)
[11ty] Wrote 0 files in 0.04 seconds (v2.0.0-canary.10)
I just started getting this error when upgrading to 2.0.0-canary.19
or 2.0.0-canary.20
. Everything was building fine up through 2.0.0-canary.18
, but now since upgrading:
[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] You’re trying to use a layout that does not exist: base (undefined) (via Error)
[11ty]
[11ty] Original error stack trace: Error: You’re trying to use a layout that does not exist: base (undefined)
[11ty] at TemplateLayoutPathResolver.getFullPath (/path/to/project/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:102:13)
[11ty] at new TemplateLayout (/path/to/project/node_modules/@11ty/eleventy/src/TemplateLayout.js:22:7)
[11ty] at TemplateLayout.getTemplate (/path/to/project/node_modules/@11ty/eleventy/src/TemplateLayout.js:47:18)
[11ty] at Template.getLayout (/path/to/project/node_modules/@11ty/eleventy/src/Template.js:126:37)
[11ty] at Template.getData (/path/to/project/node_modules/@11ty/eleventy/src/Template.js:380:25)
[11ty] at async TemplateMap.add (/path/to/project/node_modules/@11ty/eleventy/src/TemplateMap.js:60:16)
[11ty] at async Promise.all (index 3)
[11ty] at async TemplateWriter._createTemplateMap (/path/to/project/node_modules/@11ty/eleventy/src/TemplateWriter.js:243:5)
[11ty] at async TemplateWriter.generateTemplates (/path/to/project/node_modules/@11ty/eleventy/src/TemplateWriter.js:277:5)
[11ty] at async TemplateWriter.write (/path/to/project/node_modules/@11ty/eleventy/src/TemplateWriter.js:324:23)
[11ty] Wrote 0 files in 0.09 seconds (v2.0.0-canary.19)
- Here's the PR with the breaking change
- Here's the source code of my Eleventy site which is affected (which hasn't changed in 6 months)
- Here's where I set the
layouts
path in my Eleventy configuration file - Here's the base layout
- Here's the directory data file which tells all pages to use the base layout
I totally appreciate the nature of a canary release, and I accept all the risk of using an "unstable" release in production. I'm happy to refactor my source code to accommodate an upstream breaking change if there is one... either way, just wanted to share this as another case of the error identified in this issue.
@paulshryock Possibly related to https://github.com/11ty/eleventy/issues/1924 (assuming "base" isn't a layout alias; although I didn't remember seeing that alias in your /docs/eleventy.config.js file).
Agree with @pdehaan. Maybe if there is no layout found and the layout name doesn’t have an extension, Eleventy should perform the lookup anyway and report the suggested layout name in the error message?
https://www.11ty.dev/docs/layouts/#omitting-the-layouts-file-extension has more context and a way to reenable layout resolution (and why it probably isn't a good idea). I'd try changing it to "base.liquid", or creating a layout alias in your config file. 🤷
Ah, that makes perfect sense. I can just add a layout extension--I actually prefer being more specific that way. Thanks @pdehaan and @j-f1!