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

Missing layout error should report the problem template file #727

Closed
psimyn opened this issue Oct 11, 2019 · 9 comments
Closed

Missing layout error should report the problem template file #727

psimyn opened this issue Oct 11, 2019 · 9 comments

Comments

@psimyn
Copy link

psimyn commented Oct 11, 2019

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
@Ryuno-Ki
Copy link
Contributor

Could you provide a minimal working example?
(I can imagine something, but having code eases the investigation)

psimyn added a commit to psimyn/eleventy-base-blog that referenced this issue Oct 13, 2019
@psimyn
Copy link
Author

psimyn commented Oct 13, 2019

@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)

@zachleat zachleat changed the title Template error could print affected file Missing layout error should report the root problem file May 11, 2022
@zachleat zachleat changed the title Missing layout error should report the root problem file Missing layout error should report the problem template file May 11, 2022
@zachleat
Copy link
Member

zachleat commented May 11, 2022

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)

@paulshryock
Copy link
Contributor

paulshryock commented Dec 17, 2022

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)

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.

@pdehaan
Copy link
Contributor

pdehaan commented Dec 17, 2022

@paulshryock Possibly related to #1924 (assuming "base" isn't a layout alias; although I didn't remember seeing that alias in your /docs/eleventy.config.js file).

@j-f1
Copy link
Contributor

j-f1 commented Dec 17, 2022

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?

@pdehaan
Copy link
Contributor

pdehaan commented Dec 17, 2022

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. 🤷

@paulshryock
Copy link
Contributor

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!

@zachleat
Copy link
Member

Shipping with 3.0.0-alpha.17

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants