How to fix the error `found no layout file for "HTML" for "page"` in Hugo CMS?
Asked Answered
H

6

36

I recently imported content from my WordPress page into Hugo. When I run hugo serve I get following error messages:

WARN 2020/02/17 20:51:06 found no layout file for "HTML" for "page": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

The page in question starts like this:

---
linktitle: "The Title of the Post"
title: "The Title of the Post"
author: "Franz Drollig"
type: post
date: 2020-01-09T14:41:55+00:00
url: /the-title-of-post/
categories:
  - Uncategorized
weight: 10

---


This is the content of the post. This is the second sentence of the post. 

It is located in mysite/content/posts/YYYY-MM-DD-title.md.

The layouts directory is empty. However, the themes directory contains the book theme. This theme is also configured in the config.toml.

Another post, starting like shown below, is rendered correctly.

---
author: "Michael Henderson"
date: 2014-09-28
linktitle: Creating a New Theme
menu:
  main:
    parent: tutorials
next: /tutorials/github-pages-blog
prev: /tutorials/automated-deployments
title: Creating a New Theme
weight: 10
---


## Introduction

Why is my post not rendered properly? How can I fix it?

Hower answered 17/2, 2020 at 20:6 Comment(2)
I don't have experience with Hugo, but figure I'd comment if it helps to point you in the right direction. The front matter seems very different between those two documents. I'm thinking the the type: post is probably the culprit. Does it need quotes around 'post'? What happens if you remove the post front matter altogether? These links may also be helfpul: gohugo.io/content-management/front-matter and gohugo.io/templates/lookup-orderCruces
@Cruces You were right, removing type: post solved my problem. If you submit your comment as an answer, I will accept it and you will get the bounty (usually after 2-3 days).Hower
C
9

I don't have experience with Hugo, but figure I'd comment if it helps to point you in the right direction.

The front matter seems very different between those two documents. I'm thinking the type: post is probably the culprit.

What happens if you remove the post front matter altogether?

These links may also be helfpul:
Front Matter | Hugo
Hugo's Lookup Order | Hugo

Cruces answered 20/2, 2020 at 12:59 Comment(1)
Note that if you are getting this as part of release pipeline/workflow (such as a GitHub Action), you need to make sure that the checkout step also checks out the submodules which can be off by default (this is the case in the GitHub checkout action).Guitar
M
103

Okay so here is what is likely happening:

You have a theme you added as a git submodule and you recently re-cloned your project. Guess what? Your submodule needs to be re-downloaded as well.

You can do this with:

git submodule init
git submodule update

Then your project will load without errors.

Misestimate answered 16/1, 2021 at 0:15 Comment(2)
Thank you so much. THIS was the problem.Peevish
I thought this was the problem for me too, but apparently not. I also tried it as a go module and that gave me errors. :(Devisal
C
9

I don't have experience with Hugo, but figure I'd comment if it helps to point you in the right direction.

The front matter seems very different between those two documents. I'm thinking the type: post is probably the culprit.

What happens if you remove the post front matter altogether?

These links may also be helfpul:
Front Matter | Hugo
Hugo's Lookup Order | Hugo

Cruces answered 20/2, 2020 at 12:59 Comment(1)
Note that if you are getting this as part of release pipeline/workflow (such as a GitHub Action), you need to make sure that the checkout step also checks out the submodules which can be off by default (this is the case in the GitHub checkout action).Guitar
A
8

You have to create the layouts needed; by default the layout of page is named single.html, and the layout of section is named list.html.

Even if you would not use those as a real template, you have to create it in order to avoid that WARN.

So, create those files inside layout/_default: single.html list.html. Also, if you feel applied write some comment with a hugo template inside each file like this:

{{ "<!-- Layout with no content to avoid WARN message about missing page layout -->" | safeHTML }}

Arezzo answered 15/6, 2020 at 21:27 Comment(0)
C
5

If you use hugo academic theme, please try this:

$ hugo mod clean
$ hugo server

or

$ hugo mod clean
$ hugo mod get -u ./...
$ hugo server

Ref: Error: File “not found” or “failed to extract” | Troubleshooting

Cadenza answered 1/2, 2021 at 2:25 Comment(2)
this is exactly what I needed for this theme since it uses was requiring it in a go.mod and didn't use a submodule. thank you for postingFiann
This fixed it for me as well, although I'm using a different theme as a Hugo module. Running hugo mod get -u and nothing else fixed it.Dogeared
A
1

In my case, I missed this step:

echo theme = \"hugo-future-imperfect-slim\" >> config.toml

Which adds your theme to the configuration. After that, it was using the right Kinds / Layout elements from the theme. More info in the quick start: https://gohugo.io/getting-started/quick-start/

Alexandria answered 9/2, 2022 at 3:26 Comment(0)
F
0

It works well locally but I got the error when deploy on vercel. The reason is the Hugo version on Vercel is different from your local machine.

My workaround:

Find your Hugo version in your local machine by:

$ hugo version

# hugo v0.119.0-b84644c008e0dc2c4b67bd69cccf87a41a03937e+extended darwin/arm64 BuildDate=2023-09-24T15:20:17Z VendorInfo=brew`

set Environment Variable in Vercel Settings HUGO_VERSION : 0.119.0

Then in works in my case.

Reference: https://github.com/vercel/vercel/issues/7525

Fabrizio answered 28/10, 2023 at 3:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.