Cant get monorepo to build (decap, hugo)

For my site (which is down because of failed builds) https://okdrafts.netlify.app/ I wanted to use the monorepo structure to serve different versions of a given site (built with a given framework) with the least amount of data duplication.

However, I cant get the build to succeed. At first I have tried different npm build and yarn build configurations targeting the decap-hugo package folder, but now I am trying with simpler plain direct hugo commands targeting the hugocli package folder.
I’m thinking there’s some problem in my use of netlify.toml and package.json that’s messing things up, but cant seem to wrap my head around it right now.

Below is my code structure, current build settings and log

Monorepo structure.

pokho@loc:~/dev/okdrafts$ tree -L 2 .
.
├── decap-gatsby
│   ├── CODE_OF_CONDUCT.md
│   ├── CONTRIBUTING.md
│   ├── gatsby-config.js
│   ├── gatsby-node.js
│   ├── _headers
│   ├── LICENSE
│   ├── netlify
│   ├── netlify.toml
│   ├── package.json
│   ├── package-lock.json
│   ├── PULL_REQUEST_TEMPLATE.md
│   ├── README.md
│   ├── renovate.json
│   ├── src
│   └── static
├── decap-hugo
│   ├── CODE_OF_CONDUCT.md
│   ├── CONTRIBUTING.md
│   ├── cypress
│   ├── cypress.config.js
│   ├── dist
│   ├── LICENSE
│   ├── netlify.toml
│   ├── node_modules
│   ├── package.json
│   ├── postcss.config.js
│   ├── README.md
│   ├── renovate.json
│   ├── site
│   ├── src
│   ├── webpack.common.js
│   ├── webpack.dev.js
│   ├── webpack.prod.js
│   └── yarn.lock
├── hugocli
│   ├── archetypes
│   ├── assets
│   ├── content
│   ├── data
│   ├── hugo.toml
│   ├── i18n
│   ├── layouts
│   ├── netlify.toml
│   ├── public
│   ├── static
│   └── themes
├── hugo-landing-page
│   ├── config.toml
│   ├── content
│   ├── gulpfile.js
│   ├── layouts
│   ├── LICENSE
│   ├── netlify.toml
│   ├── package.json
│   ├── postcss.config.js
│   ├── public
│   ├── README.md
│   ├── src
│   ├── static
│   └── tailwind.config.js
└── README.md

Build settings
Screenshot_20240311_223244

hugocli/netlify.toml

HUGO_VERSION = "0.123.7"

[build]
publish = "public"
command = "hugo --gc --minify"

Build log

10:04:42 PM: build-image version: fcb0c1b3ada6d25c1cb58e8bc514f5f23cc14f15 (focal)
10:04:42 PM: buildbot version: 5d9cbb75e9a22173e43831f5d661d8faaf2933ce
10:04:42 PM: Fetching cached dependencies
10:04:42 PM: Starting to download cache of 7.9MB
10:04:43 PM: Finished downloading cache in 305ms
10:04:43 PM: Starting to extract cache
10:04:43 PM: Finished extracting cache in 24ms
10:04:43 PM: Finished fetching cache in 369ms
10:04:43 PM: Starting to prepare the repo for build
10:04:43 PM: Preparing Git Reference refs/heads/main
10:04:45 PM: Custom publish path detected. Proceeding with the specified path: "public"
10:04:45 PM: Custom build command detected. Proceeding with the specified command: "hugo --gc --minify"
10:04:47 PM: Starting to install dependencies
10:04:49 PM: Python version set to 3.8
10:04:49 PM: Attempting Ruby version 2.7.2, read from environment
10:04:50 PM: Using Ruby version 2.7.2
10:04:51 PM: Started restoring cached go cache
10:04:51 PM: Finished restoring cached go cache
10:04:52 PM: go version go1.19.13 linux/amd64
10:04:53 PM: Using PHP version 8.0
10:04:53 PM: Installing Hugo 0.123.8
10:04:54 PM: hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended linux/amd64 BuildDate=2024-03-07T13:14:42Z VendorInfo=gohugoio
10:04:55 PM: Downloading and installing node v18.19.1...
10:04:55 PM: Downloading https://nodejs.org/dist/v18.19.1/node-v18.19.1-linux-x64.tar.xz...
10:04:56 PM: Computing checksum with sha256sum
10:04:56 PM: Checksums matched!
10:04:58 PM: Now using node v18.19.1 (npm v10.2.4)
10:04:58 PM: Enabling Node.js Corepack
10:04:58 PM: Started restoring cached build plugins
10:04:58 PM: Finished restoring cached build plugins
10:04:58 PM: Successfully installed dependencies
10:04:58 PM: Starting build script
10:05:01 PM: Detected 0 framework(s)
10:05:01 PM: Section completed: initializing
10:05:03 PM: ​
10:05:03 PM: Netlify Build                                                 
10:05:03 PM: ────────────────────────────────────────────────────────────────
10:05:03 PM: ​
10:05:03 PM: ❯ Version
10:05:03 PM:   @netlify/build 29.36.3
10:05:03 PM: ​
10:05:03 PM: ❯ Flags
10:05:03 PM:   baseRelDir: true
10:05:03 PM:   buildId: 65ef71dfa4d96017c87c7e08
10:05:03 PM:   deployId: 65ef71dfa4d96017c87c7e0a
10:05:03 PM:   packagePath: hugocli
10:05:03 PM: ​
10:05:03 PM: ❯ Current directory
10:05:03 PM:   /opt/build/repo
10:05:03 PM: ​
10:05:03 PM: ❯ Config file
10:05:03 PM:   /opt/build/repo/hugocli/netlify.toml
10:05:03 PM: ​
10:05:03 PM: ❯ Context
10:05:03 PM:   production
10:05:03 PM: ​
10:05:03 PM: ❯ Installing plugins
10:05:03 PM:    - @netlify/plugin-lighthouse@6.0.0
10:05:15 PM: ​
10:05:15 PM: ❯ Loading plugins
10:05:15 PM:    - @netlify/plugin-lighthouse@6.0.0 from Netlify app
10:05:16 PM: ​
10:05:16 PM: build.command from netlify.toml                               
10:05:16 PM: ────────────────────────────────────────────────────────────────
10:05:16 PM: ​
10:05:16 PM: $ hugo --gc --minify
10:05:16 PM: Total in 0 ms
10:05:16 PM: Error: Unable to locate config file or config directory. Perhaps you need to create a new site.
10:05:16 PM: Run `hugo help new` for details.
10:05:16 PM: ​
10:05:16 PM: "build.command" failed                                        
10:05:16 PM: ────────────────────────────────────────────────────────────────
10:05:16 PM: ​
10:05:16 PM:   Error message
10:05:16 PM:   Command failed with exit code 1: hugo --gc --minify (https://ntl.fyi/exit-code-1)
10:05:16 PM: ​
10:05:16 PM:   Error location
10:05:16 PM:   In build.command from netlify.toml:
10:05:16 PM:   hugo --gc --minify
10:05:16 PM: ​
10:05:16 PM:   Resolved config
10:05:16 PM:   build:
10:05:16 PM:     command: hugo --gc --minify
10:05:16 PM:     commandOrigin: config
10:05:16 PM:     environment:
10:05:16 PM:       - HUGO_VERSION
10:05:16 PM:     publish: /opt/build/repo/public
10:05:16 PM:     publishOrigin: config
10:05:16 PM:   plugins:
10:05:16 PM:     - inputs: {}
10:05:16 PM:       origin: ui
10:05:16 PM:       package: "@netlify/plugin-lighthouse"
10:05:17 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
10:05:17 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:05:17 PM: Failing build: Failed to build site
10:05:17 PM: Finished processing build request in 34.854s

Package directory only reads your netlify.toml from that directory. As you can see here:

the working directory is still the root of the repo. So it looks like the build command in your Netlify UI is correct than the one in the toml.

If you only want to build the hugocli folder, you can simply set that as your base folder, remove the package directory settings and then your command from netlify.toml would work.

Thanks @hrishikesh, this workaround works but then I think I am missing the point about monorepo.

I thought the idea of monorepo was about achieving something like:

in-monorepo
├── decap-gatsby                   # Serves site1.com
├── decap-hugo                     # Serves site2.com
├── hugocli                        # Serves site3.com
├── hugo-landing-page              # Serves site4.com

Where each folder could be configured to serve the websites of a given domain or subdomain. Am I misunderstanding?

Anyway, I will follow your solution for now as I only have 1 site to build
Working build config for 1 site
Screenshot_20240315_084841

I’m not sure if I follow. You can still configure each of those folders on different sites and deploy them there and assign a domain or a subdomain. Am I missing something?

But how to do that? I couldnt find out how to configure this multi-domain for multiple folders monorepo, that’s why it is only pointing to hugocli right now.

You can create multiple sites from the same repository. Simply select the same repo when you attempt to create a new site and configure the directories for that.

How? Do you have a guide/tutorial on this?

@pinata You do it by repeatedly creating/adding a New site in Netlify, and for each one you link it to the same repository, and set the configuration as required.

So the same as adding any site:
https://docs.netlify.com/welcome/add-new-site/

It looks like you already have one where you’ve got the Base directory set to hugocli.

If you created another, you could link to the same repository, but then set the Base directory to a different path in your monorepo.