Unable to build Hugo blog for deployment

Hi! I’m trying to deploy this repo where I have a hugo blog: GitHub - RinkiyaKeDad/my-fav-quotes

But during the building phase it fails giving the following message:

9:02:49 PM: Netlify Build                                                 
9:02:49 PM: ────────────────────────────────────────────────────────────────
9:02:49 PM: ​
9:02:49 PM: ❯ Version
9:02:49 PM:   @netlify/build 29.23.5
9:02:49 PM: ​
9:02:49 PM: ❯ Flags
9:02:49 PM:   baseRelDir: true
9:02:49 PM:   buildId: 653a8697a6092d10f9731a9b
9:02:49 PM:   deployId: 653a8697a6092d10f9731a9d
9:02:49 PM: ​
9:02:49 PM: ❯ Current directory
9:02:49 PM:   /opt/build/repo
9:02:49 PM: ​
9:02:49 PM: ❯ Config file
9:02:49 PM:   /opt/build/repo/netlify.toml
9:02:49 PM: ​
9:02:49 PM: ❯ Context
9:02:49 PM:   production
9:02:49 PM: ​
9:02:49 PM: build.command from netlify.toml                               
9:02:49 PM: ────────────────────────────────────────────────────────────────
9:02:49 PM: ​
9:02:49 PM: $ hugo
9:02:49 PM: Error: Unable to locate config file or config directory. Perhaps you need to create a new site.
9:02:49 PM:        Run `hugo help new` for details.
9:02:49 PM: Total in 0 ms
9:02:49 PM: ​
9:02:49 PM: "build.command" failed                                        
9:02:49 PM: ────────────────────────────────────────────────────────────────
9:02:49 PM: ​
9:02:49 PM:   Error message
9:02:49 PM:   Command failed with exit code 255: hugo (https://ntl.fyi/exit-code-255)
9:02:49 PM: ​
9:02:49 PM:   Error location
9:02:49 PM:   In build.command from netlify.toml:
9:02:49 PM:   hugo
9:02:49 PM: ​
9:02:49 PM:   Resolved config
9:02:49 PM:   build:
9:02:49 PM:     command: hugo
9:02:49 PM:     commandOrigin: config
9:02:49 PM:     publish: /opt/build/repo/public
9:02:49 PM:     publishOrigin: config
9:02:50 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
9:02:50 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:02:50 PM: Failing build: Failed to build site
9:02:50 PM: Finished processing build request in 9.994s

Most solutions I read online talked about configuring the right path to run the build from. I am running it from the root of my repo which is where my Hugo code is. When I able to clone the repo, I am able to run hugo from the root and get access to the built site in the /public folder so I’m really confused as to what is going wrong. This is my netlify.toml:

  command = "hugo"
  publish = "public"

And my deploy build settings:

Would appreciate any help or pointers to what I might be doing incorrectly! :pray:

Hi @RinkiyaKeDad , thanks for the post and welcome.

The error occurs at the quoted line above.

In order to fix the error kindly check the stackoverflow link below regarding the same problem


Hey @clarnx! Thanks for replying. I did stumble across that StackOverflow page but didn’t understand how that relates to my problem. I am able to build the site locally by running hugo at the root of my repo. It is failing in Netlify build stage where the build command is also hugo. What do I change exactly?

Hi @RinkiyaKeDad , thanks for the feedback.
Kindly also try the suggestions at the links below as other users have also experienced the same problem when deploying to Netlify.


I found the first post also when researching for a fix and there the issue is different because the person had the wrong folder where they were running the hugo build command. I’m in the right directory. And the second post isn’t helpful either.

Thanks for the feedback @RinkiyaKeDad
At this point the best place to ask for help is the Hugo issues page on Github or the Hugo forums.
Kindly find the resources below.

I figured out what I was doing wrong. Hugo’s latest version generates the configuration in a “hugo.toml” file where as the Hugo running in the Netlify build pipeline expects the config file to be called “config.toml”. I’m not completely sure if it’s happening because of a mismatch of versions or something else but changing the file name from “hugo.toml” to “config.toml” seemed to work!

1 Like

Hi @RinkiyaKeDad , glad to know you figured out what the problem was.
Thanks for also sharing how you fixed the problem.