Home
Support Forums

Hugo - Netlify deploy error 255: Unable to find theme directory

Hi team,

I’m trying to deploy my first site using Hugo + Netlify, but I have the problem that when building, Netlify can’t find the directory of my theme used.
If I trigger a deploy directly by pushing to GitHub, it seems to work and the application is deployed, but I’ve seen that it’s not my exact configuration as I have modified some things of the theme to customize it.
I think that the problem is that when cloning my repo, the repo of the theme is not being cloned, but previously I have added it as a git submodule, so I’m empty of ideas…

He is the full log:

3:37:55 AM: Build ready to start
3:37:57 AM: build-image version: c6001ed68662a13e5deb24abec2b46058c58248a
3:37:57 AM: build-image tag: v3.9.0
3:37:57 AM: buildbot version: a46753f8a46f5779133679f5c30f3650c36322f8
3:37:57 AM: Building without cache
3:37:57 AM: Starting to prepare the repo for build
3:37:57 AM: No cached dependencies found. Cloning fresh repo
3:37:57 AM: git clone https://github.com/Pitenager/Pitesite
3:37:59 AM: Preparing Git Reference refs/heads/main
3:38:05 AM: Parsing package.json dependencies
3:38:05 AM: Starting build script
3:38:05 AM: Installing dependencies
3:38:05 AM: Python version set to 2.7
3:38:07 AM: v12.18.0 is already installed.
3:38:07 AM: Now using node v12.18.0 (npm v6.14.4)
3:38:07 AM: Started restoring cached build plugins
3:38:07 AM: Finished restoring cached build plugins
3:38:07 AM: Attempting ruby version 2.7.2, read from environment
3:38:08 AM: Using ruby version 2.7.2
3:38:09 AM: Using PHP version 5.6
3:38:09 AM: Started restoring cached go cache
3:38:09 AM: Finished restoring cached go cache
3:38:09 AM: go version go1.14.4 linux/amd64
3:38:09 AM: go version go1.14.4 linux/amd64
3:38:09 AM: Installing missing commands
3:38:09 AM: Verify run directory
3:38:09 AM: ​
3:38:09 AM: ────────────────────────────────────────────────────────────────
3:38:09 AM:   Netlify Build                                                 
3:38:09 AM: ────────────────────────────────────────────────────────────────
3:38:09 AM: ​
3:38:09 AM: ❯ Version
3:38:09 AM:   @netlify/build 18.2.4
3:38:09 AM: ​
3:38:09 AM: ❯ Flags
3:38:09 AM:   baseRelDir: true
3:38:09 AM:   deployId: 6115ccf318d8bd74c6ec7291
3:38:09 AM: ​
3:38:09 AM: ❯ Current directory
3:38:09 AM:   /opt/build/repo
3:38:09 AM: ​
3:38:09 AM: ❯ Config file
3:38:09 AM:   No config file was defined: using default values.
3:38:09 AM: ​
3:38:09 AM: ❯ Context
3:38:09 AM:   production
3:38:09 AM: ​
3:38:09 AM: ────────────────────────────────────────────────────────────────
3:38:09 AM:   1. Build command from Netlify app                             
3:38:09 AM: ────────────────────────────────────────────────────────────────
3:38:09 AM: ​
3:38:09 AM: $ hugo server -D
3:38:10 AM: Error: Unable to find theme Directory: /opt/build/repo/themes/LoveIt
3:38:10 AM: ​
3:38:10 AM: ────────────────────────────────────────────────────────────────
3:38:10 AM:   "build.command" failed                                        
3:38:10 AM: ────────────────────────────────────────────────────────────────
3:38:10 AM: ​
3:38:10 AM:   Error message
3:38:10 AM:   Command failed with exit code 255: hugo server -D
3:38:10 AM: ​
3:38:10 AM:   Error location
3:38:10 AM:   In Build command from Netlify app:
3:38:10 AM:   hugo server -D
3:38:10 AM: ​
3:38:10 AM:   Resolved config
3:38:10 AM:   build:
3:38:10 AM:     command: hugo server -D
3:38:10 AM:     commandOrigin: ui
3:38:10 AM:     publish: /opt/build/repo/public
3:38:10 AM:     publishOrigin: ui
3:38:10 AM: Caching artifacts
3:38:10 AM: Started saving build plugins
3:38:10 AM: Finished saving build plugins
3:38:10 AM: Started saving pip cache
3:38:10 AM: Finished saving pip cache
3:38:10 AM: Started saving emacs cask dependencies
3:38:10 AM: Finished saving emacs cask dependencies
3:38:10 AM: Started saving maven dependencies
3:38:10 AM: Finished saving maven dependencies
3:38:10 AM: Started saving boot dependencies
3:38:10 AM: Finished saving boot dependencies
3:38:10 AM: Started saving rust rustup cache
3:38:10 AM: Finished saving rust rustup cache
3:38:10 AM: Started saving go dependencies
3:38:10 AM: Finished saving go dependencies
3:38:13 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:38:13 AM: Creating deploy upload records
3:38:13 AM: Failing build: Failed to build site
3:38:13 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
3:38:13 AM: Finished processing build request in 15.936857368s

Thanks in advance !

Welcome to the forums @Pitenager

This is only a guess (I cannot see your git repository) but it is possible the commit of the theme you have linked to in your git submodule does not exist.

Hi coelmay,

Thank you for your fast answer.
If you want, I can grant you temporal access to the repo to help me, just need your GitHub username :slight_smile:

But I think that it exists, as if I visit de theme on my repo it follows the Link to the original one

Ok, that kind of discounts my original thought. The path (/opt/build/repo/themes/LoveIt) is correct, an is the correct case (e.g isn’t /opt/build/repo/themes/loveit or /opt/build/repo/Themes/LoveIt)?

That’s the output in my local:

/Users/admin/pitesite/themes/LoveIt

But this is how it is uploaded to GitHub:

You have 2 options:

  1. Clone the repos so they actually exist in your repo.
  2. Add a build step in Netlify like: git submodule update --recursive && hugo

Also, you’re running hugo server which is unsupported on Netlify as it starts a live server. Use only hugo.

Okay, that makes sense…
But, as I have some modifications on the original LoveIt theme, the 2nd option is not valid, right ? As it just takes the original one without my changes

Ops, true, I’ve tried hugo server and other stuff, but it’s already changed in my Netlify’s config.

Edit: I’ve tried with git submodule update --recursive && hugo and this is the result:

1:51:37 PM: Build ready to start
1:51:38 PM: build-image version: c6001ed68662a13e5deb24abec2b46058c58248a
1:51:38 PM: build-image tag: v3.9.0
1:51:38 PM: buildbot version: a46753f8a46f5779133679f5c30f3650c36322f8
1:51:39 PM: Building without cache
1:51:39 PM: Starting to prepare the repo for build
1:51:39 PM: No cached dependencies found. Cloning fresh repo
1:51:39 PM: git clone https://github.com/Pitenager/Pitesite
1:51:41 PM: Preparing Git Reference refs/heads/main
1:51:47 PM: Parsing package.json dependencies
1:51:48 PM: Starting build script
1:51:48 PM: Installing dependencies
1:51:48 PM: Python version set to 2.7
1:51:49 PM: v12.18.0 is already installed.
1:51:50 PM: Now using node v12.18.0 (npm v6.14.4)
1:51:50 PM: Started restoring cached build plugins
1:51:50 PM: Finished restoring cached build plugins
1:51:50 PM: Attempting ruby version 2.7.2, read from environment
1:51:52 PM: Using ruby version 2.7.2
1:51:52 PM: Using PHP version 5.6
1:51:52 PM: Started restoring cached go cache
1:51:52 PM: Finished restoring cached go cache
1:51:52 PM: go version go1.14.4 linux/amd64
1:51:52 PM: go version go1.14.4 linux/amd64
1:51:52 PM: Installing missing commands
1:51:52 PM: Verify run directory
1:51:53 PM: ​
1:51:53 PM: ────────────────────────────────────────────────────────────────
1:51:53 PM:   Netlify Build                                                 
1:51:53 PM: ────────────────────────────────────────────────────────────────
1:51:53 PM: ​
1:51:53 PM: ❯ Version
1:51:53 PM:   @netlify/build 18.2.4
1:51:53 PM: ​
1:51:53 PM: ❯ Flags
1:51:53 PM:   baseRelDir: true
1:51:53 PM:   deployId: 61165cc83261ad15eccdf557
1:51:53 PM: ​
1:51:53 PM: ❯ Current directory
1:51:53 PM:   /opt/build/repo
1:51:53 PM: ​
1:51:53 PM: ❯ Config file
1:51:53 PM:   No config file was defined: using default values.
1:51:53 PM: ​
1:51:53 PM: ❯ Context
1:51:53 PM:   production
1:51:53 PM: ​
1:51:53 PM: ────────────────────────────────────────────────────────────────
1:51:53 PM:   1. Build command from Netlify app                             
1:51:53 PM: ────────────────────────────────────────────────────────────────
1:51:53 PM: ​
1:51:53 PM: $ git submodule update --recursive && hugo
1:51:53 PM: Error: Unable to find theme Directory: /opt/build/repo/themes/LoveIt
1:51:53 PM: ​
1:51:53 PM: ────────────────────────────────────────────────────────────────
1:51:53 PM:   "build.command" failed                                        
1:51:53 PM: ────────────────────────────────────────────────────────────────
1:51:53 PM: ​
1:51:53 PM:   Error message
1:51:53 PM:   Command failed with exit code 255: git submodule update --recursive && hugo
1:51:53 PM: ​
1:51:53 PM:   Error location
1:51:53 PM:   In Build command from Netlify app:
1:51:53 PM:   git submodule update --recursive && hugo
1:51:53 PM: ​
1:51:53 PM:   Resolved config
1:51:53 PM:   build:
1:51:53 PM:     command: git submodule update --recursive && hugo
1:51:53 PM:     commandOrigin: ui
1:51:53 PM:     publish: /opt/build/repo/public
1:51:53 PM:     publishOrigin: ui
1:51:54 PM: Caching artifacts
1:51:54 PM: Started saving build plugins
1:51:54 PM: Finished saving build plugins
1:51:54 PM: Started saving pip cache
1:51:54 PM: Finished saving pip cache
1:51:54 PM: Started saving emacs cask dependencies
1:51:54 PM: Finished saving emacs cask dependencies
1:51:54 PM: Started saving maven dependencies
1:51:54 PM: Finished saving maven dependencies
1:51:54 PM: Started saving boot dependencies
1:51:54 PM: Finished saving boot dependencies
1:51:54 PM: Started saving rust rustup cache
1:51:54 PM: Finished saving rust rustup cache
1:51:54 PM: Started saving go dependencies
1:51:54 PM: Finished saving go dependencies
1:51:57 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:51:57 PM: Creating deploy upload records
1:51:57 PM: Failing build: Failed to build site
1:51:57 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
1:51:57 PM: Finished processing build request in 18.359634333s

Hi @Pitenager,

Yes, option 2 won’t be valid in that case. You’d have to commit that repo’s files to your repo then.

Okay, gonna try the following:
1- git clone my repo
2- remove themes directory
3- remove public directory
4- git clone LoveIt repo
5- Change the original files with the customized ones (I have backup)
6- run hugo and upload the project to GitHub
7- try another deploy

I’ll update the post with the results

Edit: No way :confused: same error…

2:17:41 PM: Build ready to start
2:17:44 PM: build-image version: c6001ed68662a13e5deb24abec2b46058c58248a
2:17:44 PM: build-image tag: v3.9.0
2:17:44 PM: buildbot version: 30fa61d2c8a7dbc51afbe773b9ba7460a9f9607a
2:17:44 PM: Building without cache
2:17:44 PM: Starting to prepare the repo for build
2:17:45 PM: No cached dependencies found. Cloning fresh repo
2:17:45 PM: git clone https://github.com/Pitenager/Pitesite
2:17:47 PM: Preparing Git Reference refs/heads/main
2:17:52 PM: Parsing package.json dependencies
2:17:52 PM: Starting build script
2:17:52 PM: Installing dependencies
2:17:52 PM: Python version set to 2.7
2:17:54 PM: v12.18.0 is already installed.
2:17:54 PM: Now using node v12.18.0 (npm v6.14.4)
2:17:54 PM: Started restoring cached build plugins
2:17:54 PM: Finished restoring cached build plugins
2:17:54 PM: Attempting ruby version 2.7.2, read from environment
2:17:56 PM: Using ruby version 2.7.2
2:17:56 PM: Using PHP version 5.6
2:17:56 PM: Started restoring cached go cache
2:17:56 PM: Finished restoring cached go cache
2:17:56 PM: go version go1.14.4 linux/amd64
2:17:56 PM: go version go1.14.4 linux/amd64
2:17:56 PM: Installing missing commands
2:17:56 PM: Verify run directory
2:17:57 PM: ​
2:17:57 PM: ────────────────────────────────────────────────────────────────
2:17:57 PM:   Netlify Build                                                 
2:17:57 PM: ────────────────────────────────────────────────────────────────
2:17:57 PM: ​
2:17:57 PM: ❯ Version
2:17:57 PM:   @netlify/build 18.2.4
2:17:57 PM: ​
2:17:57 PM: ❯ Flags
2:17:57 PM:   baseRelDir: true
2:17:57 PM:   deployId: 611662e54497801dd478521d
2:17:57 PM: ​
2:17:57 PM: ❯ Current directory
2:17:57 PM:   /opt/build/repo
2:17:57 PM: ​
2:17:57 PM: ❯ Config file
2:17:57 PM:   No config file was defined: using default values.
2:17:57 PM: ​
2:17:57 PM: ❯ Context
2:17:57 PM:   production
2:17:57 PM: ​
2:17:57 PM: ────────────────────────────────────────────────────────────────
2:17:57 PM:   1. Build command from Netlify app                             
2:17:57 PM: ────────────────────────────────────────────────────────────────
2:17:57 PM: ​
2:17:57 PM: $ hugo
2:17:57 PM: Error: Unable to find theme Directory: /opt/build/repo/themes/LoveIt
2:17:57 PM: ​
2:17:57 PM: ────────────────────────────────────────────────────────────────
2:17:57 PM:   "build.command" failed                                        
2:17:57 PM: ────────────────────────────────────────────────────────────────
2:17:57 PM: ​
2:17:57 PM:   Error message
2:17:57 PM:   Command failed with exit code 255: hugo
2:17:57 PM: ​
2:17:57 PM:   Error location
2:17:57 PM:   In Build command from Netlify app:
2:17:57 PM:   hugo
2:17:57 PM: ​
2:17:57 PM:   Resolved config
2:17:57 PM:   build:
2:17:57 PM:     command: hugo
2:17:57 PM:     commandOrigin: ui
2:17:57 PM:     publish: /opt/build/repo/public
2:17:57 PM:     publishOrigin: ui
2:17:57 PM: Caching artifacts
2:17:57 PM: Started saving build plugins
2:17:57 PM: Finished saving build plugins
2:17:57 PM: Started saving pip cache
2:17:57 PM: Finished saving pip cache
2:17:57 PM: Started saving emacs cask dependencies
2:17:57 PM: Finished saving emacs cask dependencies
2:17:57 PM: Started saving maven dependencies
2:17:57 PM: Finished saving maven dependencies
2:17:57 PM: Started saving boot dependencies
2:17:57 PM: Finished saving boot dependencies
2:17:57 PM: Started saving rust rustup cache
2:17:57 PM: Finished saving rust rustup cache
2:17:57 PM: Started saving go dependencies
2:17:57 PM: Finished saving go dependencies
2:18:00 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:18:00 PM: Creating deploy upload records
2:18:00 PM: Failing build: Failed to build site
2:18:00 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
2:18:00 PM: Finished processing build request in 16.162701643s

Okay I think I’ve reached the solution !!

Steps:

  1. Delete LoveIt directory: sudo rm -r themes/LoveIt
  2. Delete public directory: sudo rm -r public/
  3. Clone the LoveIt’s repository in the themes/ directory: git clone https://github.com/dillonzq/LoveIt.git
  4. Change the default’s files of the theme with my own customized ones
  5. Remove ALL git files from the theme directory (.git, .gitignore and .github)
  6. Commit the changes to my repo
  7. Push to my repo
  8. Trigger another deploy

And that’s the result: https://pitenager.netlify.app

Thank you everyone ! :slight_smile:

1 Like