NextJS deployment within a monorepo

Hello,

Site name : 635199241a757500084ec99c--majestic-chimera-d1dee7.netlify.app/

I am trying to create the CI for a NextJS build from a mono repo. I have a netlify.toml at the base of my repo. I have tried setting the base directory to base = "apps/web" but it fails on the husky prepare script. Any Ideas?

File Structure

apps/
> web/
>> .next/
> server/
netlify.toml
package.json
etc

netlify.toml

# Settings in the [build] context are global and are applied to
# all contexts unless otherwise overridden by more specific contexts.
[build]
  # Directory to change to before starting a build.
  # This is where we will look for package.json/.nvmrc/etc.
  # If not set, defaults to the root directory.
  # base = "apps/web"

  # Directory that contains the deploy-ready HTML files and
  # assets generated by the build. This is relative to the base
  # directory if one has been set, or the root directory if
  # a base has not been set. This sample publishes the directory
  # located at the absolute path "root/project/build-output"

  publish = "apps/web/.next"

  # Default build command.
  command = "npm run build"

So the build completes. But the site does not render. I believe this is because I don’t have the right publish directory

Page Not Found
Looks like you’ve followed a broken link or entered a URL that doesn’t exist on this site.

This is the log

Deploy log
Preview
2:53:24 PM: Build ready to start
2:53:31 PM: build-image version: d05976bd3309b73a86eaa327bf80e105ff13f5e4 (focal)
2:53:31 PM: build-image tag: v4.13.0
2:53:31 PM: buildbot version: f9b3ce49f3adc0f38a145dbc82e4c63f31681c42
2:53:31 PM: Fetching cached dependencies
2:53:31 PM: Starting to download cache of 137.4MB
2:53:32 PM: Finished downloading cache in 1.550749419s
2:53:32 PM: Starting to extract cache
2:53:34 PM: Finished extracting cache in 1.211448932s
2:53:34 PM: Finished fetching cache in 2.804325931s
2:53:34 PM: Starting to prepare the repo for build
2:53:34 PM: Preparing Git Reference refs/heads/main
2:53:34 PM: Parsing package.json dependencies
2:53:35 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'apps/web/.next' versus '' in the Netlify UI
2:53:35 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'npm run build' versus '' in the Netlify UI
2:53:35 PM: Starting build script
2:53:35 PM: Installing dependencies
2:53:35 PM: Python version set to 2.7
2:53:36 PM: Started restoring cached node version
2:53:36 PM: Finished restoring cached node version
2:53:37 PM: v16.18.0 is already installed.
2:53:37 PM: Now using node v16.18.0 (npm v8.19.2)
2:53:37 PM: Enabling node corepack
2:53:37 PM: Started restoring cached build plugins
2:53:37 PM: Finished restoring cached build plugins
2:53:37 PM: Attempting ruby version 2.7.2, read from environment
2:53:38 PM: Using ruby version 2.7.2
2:53:38 PM: Using PHP version 8.0
2:53:38 PM: No npm workspaces detected
2:53:38 PM: Started restoring cached node modules
2:53:38 PM: Finished restoring cached node modules
2:53:39 PM: Started restoring cached go cache
2:53:39 PM: Finished restoring cached go cache
2:53:39 PM: Installing Go version 1.17 (requested 1.17)
2:53:44 PM: unset GOOS;
2:53:44 PM: unset GOARCH;
2:53:44 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
2:53:44 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
2:53:44 PM: go version >&2;
2:53:44 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
2:53:44 PM: go version go1.17 linux/amd64
2:53:44 PM: Installing missing commands
2:53:44 PM: Verify run directory
2:53:45 PM: ​
2:53:45 PM: ────────────────────────────────────────────────────────────────
2:53:45 PM:   Netlify Build                                                 
2:53:45 PM: ────────────────────────────────────────────────────────────────
2:53:45 PM: ​
2:53:45 PM: ❯ Version
2:53:45 PM:   @netlify/build 28.1.1
2:53:45 PM: ​
2:53:45 PM: ❯ Flags
2:53:45 PM:   baseRelDir: true
2:53:45 PM:   buildId: 635199241a757500084ec99a
2:53:45 PM:   deployId: 635199241a757500084ec99c
2:53:45 PM: ​
2:53:45 PM: ❯ Current directory
2:53:45 PM:   /opt/build/repo
2:53:45 PM: ​
2:53:45 PM: ❯ Config file
2:53:45 PM:   /opt/build/repo/netlify.toml
2:53:45 PM: ​
2:53:45 PM: ❯ Context
2:53:45 PM:   production
2:53:45 PM: ​
2:53:45 PM: ────────────────────────────────────────────────────────────────
2:53:45 PM:   1. build.command from netlify.toml                            
2:53:45 PM: ────────────────────────────────────────────────────────────────
2:53:45 PM: ​
2:53:45 PM: $ npm run build
2:53:45 PM: > shatzen@0.0.0 build
2:53:45 PM: > turbo run build
2:53:45 PM: • Packages in scope: eslint-config-custom, server, tsconfig, web
2:53:45 PM: • Running build in 4 packages
2:53:45 PM: • Remote caching disabled
2:53:45 PM: web:build: cache miss, executing 014407b0ff64c0d3
2:53:45 PM: web:build: 
2:53:45 PM: web:build: > web@0.1.0 build
2:53:45 PM: web:build: > next build
2:53:45 PM: web:build: 
2:53:46 PM: web:build: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2:53:46 PM: web:build: info  - Linting and checking validity of types...
2:53:49 PM: web:build: info  - Creating an optimized production build...
2:53:56 PM: web:build: info  - Compiled successfully
2:53:56 PM: web:build: info  - Collecting page data...
2:53:57 PM: web:build: info  - Generating static pages (0/5)
2:53:58 PM: web:build: info  - Generating static pages (1/5)
2:53:58 PM: web:build: info  - Generating static pages (2/5)
2:53:58 PM: web:build: info  - Generating static pages (3/5)
2:53:58 PM: web:build: info  - Generating static pages (5/5)
2:53:59 PM: web:build: info  - Finalizing page optimization...
2:53:59 PM: web:build: 
2:53:59 PM: web:build: Route (pages)                              Size     First Load JS
2:53:59 PM: web:build: ┌ ○ / (552 ms)                             2.48 kB         140 kB
2:53:59 PM: web:build: ├   /_app                                  0 B             106 kB
2:53:59 PM: web:build: ├ ○ /404                                   193 B           106 kB
2:53:59 PM: web:build: ├ λ /api/hello                             0 B             106 kB
2:53:59 PM: web:build: ├ ○ /login/[uuid] (512 ms)                 2.21 kB         139 kB
2:53:59 PM: web:build: └ ○ /room/[room] (459 ms)                  2.73 kB         140 kB
2:53:59 PM: web:build: + First Load JS shared by all              108 kB
2:53:59 PM: web:build:   ├ chunks/framework-1470d73b4587dc44.js   44.9 kB
2:53:59 PM: web:build:   ├ chunks/main-7eb41630595c1fa6.js        31 kB
2:53:59 PM: web:build:   ├ chunks/pages/_app-c4bdedb4840b01b1.js  28.9 kB
2:53:59 PM: web:build:   ├ chunks/webpack-9b312e20a4e32339.js     836 B
2:53:59 PM: web:build:   └ css/97f49350277676a7.css               2.74 kB
2:53:59 PM: web:build: 
2:53:59 PM: web:build: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
2:53:59 PM: web:build: ○  (Static)  automatically rendered as static HTML (uses no initial props)
2:53:59 PM: web:build: 
2:53:59 PM:  Tasks:    1 successful, 1 total
2:53:59 PM: Cached:    0 cached, 1 total
2:53:59 PM:   Time:    13.614s
2:53:59 PM: ​
2:53:59 PM: (build.command completed in 13.8s)
2:53:59 PM: ​
2:53:59 PM: ────────────────────────────────────────────────────────────────
2:53:59 PM:   2. Deploy site                                                
2:53:59 PM: ────────────────────────────────────────────────────────────────
2:53:59 PM: ​
2:53:59 PM: Starting to deploy site from 'apps/web/.next'
2:53:59 PM: Creating deploy tree 
2:53:59 PM: Creating deploy upload records
2:53:59 PM: 15 new files to upload
2:53:59 PM: 0 new functions to upload
2:53:59 PM: Site deploy was successfully initiated
2:53:59 PM: ​
2:53:59 PM: (Deploy site completed in 690ms)
2:53:59 PM: ​
2:53:59 PM: ────────────────────────────────────────────────────────────────
2:53:59 PM:   Netlify Build Complete                                        
2:53:59 PM: ────────────────────────────────────────────────────────────────
2:53:59 PM: ​
2:53:59 PM: (Netlify Build completed in 14.5s)
2:54:00 PM: Starting post processing
2:54:00 PM: Caching artifacts
2:54:00 PM: Started saving node modules
2:54:00 PM: Finished saving node modules
2:54:00 PM: Started saving build plugins
2:54:00 PM: Finished saving build plugins
2:54:00 PM: Started saving pip cache
2:54:00 PM: Finished saving pip cache
2:54:00 PM: Started saving emacs cask dependencies
2:54:00 PM: Finished saving emacs cask dependencies
2:54:00 PM: Started saving maven dependencies
2:54:00 PM: Finished saving maven dependencies
2:54:00 PM: Started saving boot dependencies
2:54:00 PM: Post processing - HTML
2:54:00 PM: Finished saving boot dependencies
2:54:00 PM: Started saving rust rustup cache
2:54:00 PM: Finished saving rust rustup cache
2:54:00 PM: Started saving go dependencies
2:54:00 PM: Finished saving go dependencies
2:54:00 PM: Build script success
2:54:00 PM: Post processing - header rules
2:54:00 PM: Post processing - redirect rules
2:54:00 PM: Post processing done
2:54:01 PM: Uploading Cache of size 139.8MB
2:54:02 PM: Finished processing build request in 30.954063314s
2:54:03 PM: Site is live ✨

You most likely need this: