"Could not find a production build" NextJS in NX Monorepo

Site-name : ouigroup-client-dashboard-stg

I’ve setup a NX repository with a NextJS app inside. I tried to configure a Gitlab pipeline for the automated deployment process but I failed so far.

I tried to deploy locally and tried to get through the problem but I also failed, I get the error :

“Could not find a production build in the ‘/builds/ouigroup/client-dashboard/dist/apps/front-nextjs/.next’ directory. Try building your app with ‘next build’ before starting the production server. Could not find a production build | Next.js

I have a rather short netlify.toml

[build]
  publish = "dist/apps/front-nextjs/.next"
  command = "nx build front-nextjs"

[[plugins]]
  package = "@netlify/plugin-nextjs"

I used the latest netlify/plugin-nextjs and tried the 4.25 as mentionned in a previous topic but it doesn’t work either.

Build logs :

8:59:19 AM: build-image version: 1ca34a93198b041e44214013884c57d146a23fed (focal)
8:59:19 AM: build-image tag: v4.16.4
8:59:19 AM: buildbot version: 2577a19e1559072eeb7a6727cec389b63b90401c
8:59:19 AM: Fetching cached dependencies
8:59:19 AM: Failed to fetch cache, continuing with build
8:59:19 AM: Starting to prepare the repo for build
8:59:19 AM: No cached dependencies found. Cloning fresh repo
8:59:19 AM: git clone --filter=blob:none --no-checkout git@gitlab.com:ouigroup/client-dashboard
8:59:20 AM: Preparing Git Reference refs/heads/stg
8:59:22 AM: Parsing package.json dependencies
8:59:23 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'nx build front-nextjs' versus 'yarn build' in the Netlify UI
8:59:23 AM: Starting build script
8:59:23 AM: Installing dependencies
8:59:23 AM: Python version set to 2.7
8:59:23 AM: v16.19.0 is already installed.
8:59:24 AM: Now using node v16.19.0 (npm v8.19.3)
8:59:24 AM: Enabling Node.js Corepack
8:59:24 AM: Started restoring cached build plugins
8:59:24 AM: Finished restoring cached build plugins
8:59:24 AM: Attempting Ruby version 2.7.2, read from environment
8:59:25 AM: Using Ruby version 2.7.2
8:59:25 AM: Using PHP version 8.0
8:59:25 AM: Started restoring cached corepack dependencies
8:59:25 AM: mv: cannot move '/opt/build/cache/.node/corepack' to '/opt/buildhome/.node/corepack': No such file or directory
8:59:25 AM: Finished restoring cached corepack dependencies
8:59:25 AM: Started restoring cached yarn cache
8:59:25 AM: Finished restoring cached yarn cache
8:59:26 AM: No yarn workspaces detected
8:59:26 AM: Started restoring cached node modules
8:59:26 AM: Finished restoring cached node modules
8:59:26 AM: Installing npm packages using Yarn version 1.22.19
8:59:26 AM: yarn install v1.22.19
8:59:26 AM: [1/4] Resolving packages...
8:59:26 AM: [2/4] Fetching packages...
8:59:53 AM: [3/4] Linking dependencies...
8:59:53 AM: warning "@nrwl/next > @babel/plugin-proposal-decorators@7.20.7" has unmet peer dependency "@babel/core@^7.0.0-0".
8:59:53 AM: warning "@nrwl/next > url-loader@4.1.1" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
8:59:53 AM: warning "@nrwl/next > @babel/plugin-proposal-decorators > @babel/helper-create-class-features-plugin@7.20.12" has unmet peer dependency "@babel/core@^7.0.0".
8:59:53 AM: warning "@nrwl/next > @babel/plugin-proposal-decorators > @babel/plugin-syntax-decorators@7.19.0" has unmet peer dependency "@babel/core@^7.0.0-0".
8:59:53 AM: warning "@nrwl/next > @nrwl/webpack > babel-loader@8.3.0" has unmet peer dependency "@babel/core@^7.0.0".
8:59:53 AM: warning " > @babel/preset-react@7.18.6" has unmet peer dependency "@babel/core@^7.0.0-0".
8:59:53 AM: warning "babel-jest > babel-preset-jest@28.1.3" has unmet peer dependency "@babel/core@^7.0.0".
8:59:53 AM: warning " > bootstrap@5.2.3" has unmet peer dependency "@popperjs/core@^2.11.6".
8:59:53 AM: warning "@nrwl/web > @nrwl/vite@15.4.5" has unmet peer dependency "vite@^4.0.1".
8:59:53 AM: warning "@nrwl/web > @nrwl/vite@15.4.5" has unmet peer dependency "vitest@^0.25.8".
8:59:53 AM: warning " > @testing-library/react-hooks@8.0.1" has incorrect peer dependency "react@^16.9.0 || ^17.0.0".
8:59:53 AM: warning " > babel-jest@28.1.1" has unmet peer dependency "@babel/core@^7.8.0".
9:00:13 AM: [4/4] Building fresh packages...
9:00:27 AM: $ husky install
9:00:27 AM: husky - Git hooks installed
9:00:27 AM: Done in 61.15s.
9:00:27 AM: npm packages installed using Yarn
9:00:27 AM: Started restoring cached go cache
9:00:27 AM: Finished restoring cached go cache
9:00:27 AM: go version go1.19.5 linux/amd64
9:00:28 AM: Detected 1 framework(s)
9:00:28 AM: "next-nx" at version "15.4.5"
9:00:28 AM: Installing missing commands
9:00:28 AM: Verify run directory
9:00:28 AM: Section completed: initializing
9:00:29 AM: ​
9:00:29 AM:   Netlify Build                                                 
9:00:29 AM: ────────────────────────────────────────────────────────────────
9:00:29 AM: ​
9:00:29 AM: ❯ Version
9:00:29 AM:   @netlify/build 29.5.1
9:00:29 AM: ​
9:00:29 AM: ❯ Flags
9:00:29 AM:   baseRelDir: true
9:00:29 AM:   buildId: 63d0e155f614120008b0b196
9:00:29 AM:   deployId: 63d0e155f614120008b0b198
9:00:29 AM: ​
9:00:29 AM: ❯ Current directory
9:00:29 AM:   /opt/build/repo
9:00:29 AM: ​
9:00:29 AM: ❯ Config file
9:00:29 AM:   /opt/build/repo/netlify.toml
9:00:29 AM: ​
9:00:29 AM: ❯ Context
9:00:29 AM:   branch-deploy
9:00:30 AM: ​
9:00:30 AM: ❯ Using Next.js Runtime - v4.25.0
9:00:30 AM: ​
9:00:30 AM: ❯ Outdated plugins
9:00:30 AM:    - @netlify/plugin-nextjs@4.25.0: latest version is 4.30.1
9:00:30 AM:      To upgrade this plugin, please update its version in "package.json"
9:00:31 AM: ​
9:00:31 AM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
9:00:31 AM: ────────────────────────────────────────────────────────────────
9:00:31 AM: ​
9:00:31 AM: No Next.js cache to restore.
9:00:31 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
9:00:31 AM: ​
9:00:31 AM: (@netlify/plugin-nextjs onPreBuild completed in 18ms)
9:00:31 AM: ​
9:00:31 AM:   2. build.command from netlify.toml                            
9:00:31 AM: ────────────────────────────────────────────────────────────────
9:00:31 AM: ​
9:00:31 AM: $ nx build front-nextjs
9:00:32 AM: > nx run front-nextjs:build:production  [remote cache]
9:00:32 AM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
9:00:32 AM: Attention: Next.js now collects completely anonymous telemetry regarding usage.
9:00:32 AM: This information is used to shape Next.js' roadmap and prioritize features.You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:https://nextjs.org/telemetry
9:00:32 AM: info  - Skipping linting
9:00:32 AM: info  - Checking validity of types...
9:00:32 AM: info  - Creating an optimized production build...
9:00:32 AM: info  - Compiled successfully
9:00:32 AM: info  - Collecting page data...
9:00:32 AM: info  - Generating static pages (0/4)
9:00:32 AM: info  - Generating static pages (1/4)
9:00:32 AM: info  - Generating static pages (2/4)
9:00:32 AM: info  - Generating static pages (3/4)
9:00:32 AM: info  - Generating static pages (4/4)
9:00:32 AM: info  - Finalizing page optimization...
9:00:32 AM: Route (pages)                              Size     First Load JS
9:00:32 AM: ┌ λ /                                      4.7 kB          233 kB
9:00:32 AM: ├   /_app                                  0 B             229 kB
9:00:32 AM: ├ ○ /404                                   181 B           229 kB
9:00:32 AM: ├ λ /api/get-challenge-detail              0 B             229 kB
9:00:32 AM: ├ λ /challenge/[challengeId]               4.76 kB         233 kB
9:00:32 AM: ├ λ /challenge/[challengeId]/rankings      5.39 kB         239 kB
9:00:32 AM: ├ λ /login                                 27.1 kB         261 kB
9:00:32 AM: └ λ /logout                                830 B           230 kB
9:00:32 AM: + First Load JS shared by all              256 kB
9:00:32 AM:   ├ chunks/framework-93435e5523790c31.js   45.4 kB
9:00:32 AM:   ├ chunks/main-034306150322ded5.js        27.8 kB
9:00:32 AM:   ├ chunks/pages/_app-40deb7e64d609f13.js  155 kB
9:00:32 AM:   ├ chunks/webpack-f164db4954bac6ec.js     826 B
9:00:32 AM:   └ css/e2301e1eec10018a.css               27.5 kB
9:00:32 AM: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
9:00:32 AM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
9:00:32 AM:  >  NX   Successfully ran target build for project front-nextjs
9:00:32 AM:    Nx read the output from the cache instead of running the command for 1 out of 1 tasks.
9:00:33 AM:    Nx Cloud made it possible to reuse front-nextjs: https://cloud.nx.app/runs/Pg0CsBAw5W
9:00:33 AM: ​
9:00:33 AM: (build.command completed in 1.4s)
9:00:33 AM: ​
9:00:33 AM:   3. @netlify/plugin-nextjs (onBuild event)                     
9:00:33 AM: ────────────────────────────────────────────────────────────────
9:00:33 AM: ​
9:00:33 AM: Patching /opt/build/repo/node_modules/next/dist/server/base-server.js
9:00:33 AM: Done
9:00:33 AM: Patching /opt/build/repo/node_modules/next/dist/server/next-server.js
9:00:33 AM: Done
9:00:33 AM: Moving static page files to serve from CDN...
9:00:33 AM: Moved 0 files
9:00:33 AM: Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.
9:00:33 AM: Netlify configuration property "redirects" value changed to [
9:00:33 AM:   { from: '/_next/static/*', to: '/static/:splat', status: 200 },
9:00:33 AM:   {
9:00:33 AM:     from: '/:locale/_next/static/*',
9:00:33 AM:     to: '/static/:splat',
9:00:33 AM:     status: 200
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/_next/image*',
9:00:33 AM:     query: { url: ':url', w: ':width', q: ':quality' },
9:00:33 AM:     to: '/_ipx/w_:width,q_:quality/:url',
9:00:33 AM:     status: 301
9:00:33 AM:   },
9:00:33 AM:   { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
9:00:33 AM:   { from: '/cache/*', to: '/404.html', status: 404, force: true },
9:00:33 AM:   { from: '/server/*', to: '/404.html', status: 404, force: true },
9:00:33 AM:   { from: '/serverless/*', to: '/404.html', status: 404, force: true },
9:00:33 AM:   { from: '/trace', to: '/404.html', status: 404, force: true },
9:00:33 AM:   { from: '/traces', to: '/404.html', status: 404, force: true },
9:00:33 AM:   {
9:00:33 AM:     from: '/routes-manifest.json',
9:00:33 AM:     to: '/404.html',
9:00:33 AM:     status: 404,
9:00:33 AM:     force: true
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/build-manifest.json',
9:00:33 AM:     to: '/404.html',
9:00:33 AM:     status: 404,
9:00:33 AM:     force: true
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/prerender-manifest.json',
9:00:33 AM:     to: '/404.html',
9:00:33 AM:     status: 404,
9:00:33 AM:     force: true
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/react-loadable-manifest.json',
9:00:33 AM:     to: '/404.html',
9:00:33 AM:     status: 404,
9:00:33 AM:     force: true
9:00:33 AM:   },
9:00:33 AM:   { from: '/BUILD_ID', to: '/404.html', status: 404, force: true },
9:00:33 AM:   {
9:00:33 AM:     from: '/',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: true,
9:00:33 AM:     conditions: { Cookie: [Array] }
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/api',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/api/*',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/*',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     conditions: { Cookie: [Array] },
9:00:33 AM:     force: true
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/_next/data/PinYGg18YSylG1QZfWD_N/fr/index.json',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/_next/data/PinYGg18YSylG1QZfWD_N/fr/login.json',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/login',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/_next/data/PinYGg18YSylG1QZfWD_N/fr/logout.json',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/logout',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/_next/data/PinYGg18YSylG1QZfWD_N/fr/challenge/:challengeId.json',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/challenge/:challengeId',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/_next/data/PinYGg18YSylG1QZfWD_N/fr/challenge/:challengeId/rankings.json',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/challenge/:challengeId/rankings',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200,
9:00:33 AM:     force: false
9:00:33 AM:   },
9:00:33 AM:   {
9:00:33 AM:     from: '/*',
9:00:33 AM:     to: '/.netlify/functions/___netlify-handler',
9:00:33 AM:     status: 200
9:00:33 AM:   }
9:00:33 AM: ].
9:00:33 AM: ​
9:00:33 AM: (@netlify/plugin-nextjs onBuild completed in 58ms)
9:00:33 AM: ​
9:00:33 AM:   4. Functions bundling                                         
9:00:33 AM: ────────────────────────────────────────────────────────────────
9:00:33 AM: ​
9:00:33 AM: Packaging Functions from .netlify/functions-internal directory:
9:00:33 AM:  - ___netlify-handler/___netlify-handler.js
9:00:33 AM:  - ___netlify-odb-handler/___netlify-odb-handler.js
9:00:33 AM:  - _ipx/_ipx.js
9:00:33 AM: ​
9:00:57 AM: ​
9:00:57 AM: (Functions bundling completed in 24.5s)
9:00:57 AM: ​
9:00:57 AM:   5. Edge Functions bundling                                    
9:00:57 AM: ────────────────────────────────────────────────────────────────
9:00:57 AM: ​
9:00:57 AM: Packaging Edge Functions from .netlify/edge-functions directory:
9:00:57 AM:  - ipx
9:00:59 AM: ​
9:00:59 AM: (Edge Functions bundling completed in 1.8s)
9:00:59 AM: ​
9:00:59 AM:   6. @netlify/plugin-nextjs (onPostBuild event)                 
9:00:59 AM: ────────────────────────────────────────────────────────────────
9:00:59 AM: ​
9:00:59 AM: Next.js cache saved.
9:00:59 AM: ​
9:00:59 AM: (@netlify/plugin-nextjs onPostBuild completed in 159ms)
9:00:59 AM: ​
9:00:59 AM:   7. Deploy site                                                
9:00:59 AM: ────────────────────────────────────────────────────────────────
9:00:59 AM: ​
9:00:59 AM: Starting to deploy site from 'dist/apps/front-nextjs/.next'
9:00:59 AM: Calculating files to upload
9:01:00 AM: 1 new files to upload
9:01:00 AM: 3 new functions to upload
9:01:07 AM: Section completed: deploying
9:01:07 AM: Site deploy was successfully initiated
9:01:07 AM: ​
9:01:07 AM: (Deploy site completed in 7.8s)
9:01:07 AM: ​
9:01:07 AM:   Netlify Build Complete                                        
9:01:07 AM: ────────────────────────────────────────────────────────────────
9:01:07 AM: ​
9:01:07 AM: Starting post processing
9:01:07 AM: (Netlify Build completed in 37.7s)
9:01:07 AM: Caching artifacts
9:01:07 AM: Post processing - HTML
9:01:07 AM: Started saving node modules
9:01:07 AM: Finished saving node modules
9:01:07 AM: Started saving build plugins
9:01:07 AM: Finished saving build plugins
9:01:08 AM: Post processing - header rules
9:01:07 AM: Started saving yarn cache
9:01:08 AM: Post processing - redirect rules
9:01:08 AM: Post processing done
9:01:08 AM: Section completed: postprocessing
9:01:09 AM: Site is live ✨
9:01:13 AM: Finished saving yarn cache
9:01:13 AM: Started saving pip cache
9:01:14 AM: Finished saving pip cache
9:01:14 AM: Started saving emacs cask dependencies
9:01:14 AM: Finished saving emacs cask dependencies
9:01:14 AM: Started saving maven dependencies
9:01:14 AM: Finished saving maven dependencies
9:01:14 AM: Started saving boot dependencies
9:01:14 AM: Finished saving boot dependencies
9:01:14 AM: Started saving rust rustup cache
9:01:14 AM: Finished saving rust rustup cache
9:01:14 AM: Started saving go dependencies
9:01:14 AM: Finished saving go dependencies
9:01:14 AM: Build script success
9:01:14 AM: Section completed: building
9:01:21 AM: Uploading Cache of size 1.3GB
9:01:28 AM: Section completed: cleanup
9:01:28 AM: Finished processing build request in 2m9.689s

Hi @Labric :wave:t6: ,

Welcome to the the forums! Did you try changing your build command to --skip-nx-cache ?

1 Like

I tried but unfortunately the error remain.
Here are my CI logs

Running with gitlab-runner 15.6.0~beta.186.ga889181a (a889181a)
  on blue-3.shared.runners-manager.gitlab.com/default zxwgkjAP
Preparing the "docker+machine" executor
00:32
Using Docker executor with image node:16.17.0 ...
Pulling docker image node:16.17.0 ...
Using docker image sha256:e90654c3952418c8110d9922de4c6b2723a79485f787e3741934f695e8518092 for node:16.17.0 with digest node@sha256:a5d9200d3b8c17f0f3d7717034a9c215015b7aae70cb2a9d5e5dae7ff8aa6ca8 ...
Preparing environment
00:03
Running on runner-zxwgkjap-project-42480856-concurrent-0 via runner-zxwgkjap-shared-1675252343-86ad60d9...
Getting source from Git repository
00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/ouigroup/client-dashboard/.git/
Created fresh repository.
Checking out ca669aaf as dev...
Skipping Git submodules setup
Restoring cache
00:49
Checking cache for 0-64be85f1fc9d4d8946bb4722756eb32241d3ad50-non_protected...
Downloading cache.zip from https://storage.googleapis.com/gitlab-com-runners-cache/project/42480856/0-64be85f1fc9d4d8946bb4722756eb32241d3ad50-non_protected 
Successfully extracted cache
Downloading artifacts
00:02
Downloading artifacts for workspace-lint (3696200348)...
Downloading artifacts from coordinator... ok        id=3696200348 responseStatus=200 OK token=64_DyWmn
Downloading artifacts for format-check (3696200350)...
Downloading artifacts from coordinator... ok        id=3696200350 responseStatus=200 OK token=64_DyWmn
Downloading artifacts for lint (3696200351)...
Downloading artifacts from coordinator... ok        id=3696200351 responseStatus=200 OK token=64_DyWmn
Downloading artifacts for test (3696200353)...
Downloading artifacts from coordinator... ok        id=3696200353 responseStatus=200 OK token=64_DyWmn
Executing "step_script" stage of the job script
08:08
Using docker image sha256:e90654c3952418c8110d9922de4c6b2723a79485f787e3741934f695e8518092 for node:16.17.0 with digest node@sha256:a5d9200d3b8c17f0f3d7717034a9c215015b7aae70cb2a9d5e5dae7ff8aa6ca8 ...
$ yarn install --cache-folder .yarn-cache --prefer-offline --frozen-lockfile
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "@nrwl/next > url-loader@4.1.1" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > bootstrap@5.2.3" has unmet peer dependency "@popperjs/core@^2.11.6".
warning "@storybook/addon-actions > react-inspector@5.1.1" has incorrect peer dependency "react@^16.8.4 || ^17.0.0".
warning "@storybook/addon-docs > @mdx-js/react@1.6.22" has incorrect peer dependency "react@^16.13.1 || ^17.0.0".
warning "@storybook/addon-docs > babel-loader@8.3.0" has unmet peer dependency "webpack@>=2".
warning " > html-webpack-plugin@5.5.0" has unmet peer dependency "webpack@^5.20.0".
warning " > @storybook/react@6.5.16" has unmet peer dependency "require-from-string@^2.0.2".
warning "@storybook/react > react-element-to-jsx-string@14.3.4" has incorrect peer dependency "react@^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1".
warning "@storybook/react > react-element-to-jsx-string@14.3.4" has incorrect peer dependency "react-dom@^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1".
warning " > @testing-library/react-hooks@8.0.1" has incorrect peer dependency "react@^16.9.0 || ^17.0.0".
warning " > babel-loader@8.1.0" has unmet peer dependency "webpack@>=2".
warning " > url-loader@3.0.0" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
[4/4] Building fresh packages...
$ husky install
husky - Git hooks installed
Done in 223.38s.
$ NX_HEAD=$CI_COMMIT_SHA
$ NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}
$ npm install -g netlify-cli
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
added 1464 packages, and audited 1465 packages in 43s
192 packages are looking for funding
  run `npm fund` for details
18 vulnerabilities (1 low, 10 moderate, 7 high)
To address issues that do not require attention, run:
  npm audit fix
To address all issues possible (including breaking changes), run:
  npm audit fix --force
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
$ netlify deploy --build --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --alias $CI_ENVIRONMENT_SLUG
​
  Netlify Build                                                 
────────────────────────────────────────────────────────────────
​
❯ Version
  @netlify/build 29.5.2
​
❯ Flags
  {}
​
❯ Current directory
  /builds/ouigroup/client-dashboard
​
❯ Config file
  /builds/ouigroup/client-dashboard/netlify.toml
​
❯ Context
  dev
​
❯ Using Next.js Runtime - v4.30.3
​
  1. @netlify/plugin-nextjs (onPreBuild event)                  
────────────────────────────────────────────────────────────────
​
No Next.js cache to restore.
Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
​
(@netlify/plugin-nextjs onPreBuild completed in 616ms)
​
  2. build.command from netlify.toml                            
────────────────────────────────────────────────────────────────
​
$ nx build front --skip-nx-cache
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
> nx run front:build:production
warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
info  - Skipping linting
info  - Checking validity of types...
info  - Creating an optimized production build...
[BABEL] Note: The code generator has deoptimised the styling of /builds/ouigroup/client-dashboard/libs/ui/src/components/assets/languages/flags/portugal.svg as it exceeds the max of 500KB.
[BABEL] Note: The code generator has deoptimised the styling of undefined as it exceeds the max of 500KB.
[BABEL] Note: The code generator has deoptimised the styling of /builds/ouigroup/client-dashboard/libs/ui/src/components/assets/languages/flags/portugal.svg as it exceeds the max of 500KB.
[BABEL] Note: The code generator has deoptimised the styling of undefined as it exceeds the max of 500KB.
info  - Compiled successfully
info  - Collecting page data...
info  - Generating static pages (0/2)
info  - Generating static pages (2/2)
info  - Finalizing page optimization...
Route (pages)                              Size     First Load JS
┌ λ /                                      4.64 kB         214 kB
├   /_app                                  0 B             209 kB
├ ○ /404                                   181 B           209 kB
├ λ /challenge/[challengeId]               4.69 kB         214 kB
├ λ /challenge/[challengeId]/rankings      10.5 kB         220 kB
├ λ /login                                 30.4 kB         239 kB
└ λ /logout                                831 B           210 kB
+ First Load JS shared by all              237 kB
  ├ chunks/framework-93435e5523790c31.js   45.4 kB
  ├ chunks/main-d309b8651496a8ed.js        27.1 kB
  ├ chunks/pages/_app-76da91bea718aa4a.js  136 kB
  ├ chunks/webpack-f164db4954bac6ec.js     826 B
  └ css/e2301e1eec10018a.css               27.5 kB
λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
 
 >  NX   Successfully ran target build for project front
   View logs and investigate cache misses at https://cloud.nx.app/runs/psBf3MasT0
​
(build.command completed in 2m 10.6s)
​
  3. @netlify/plugin-nextjs (onBuild event)                     
────────────────────────────────────────────────────────────────
​
Patching /builds/ouigroup/client-dashboard/node_modules/next/dist/server/base-server.js
Done
Patching /builds/ouigroup/client-dashboard/node_modules/next/dist/server/next-server.js
Done
Moving static page files to serve from CDN...
Moved 0 files
Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.
Netlify configuration property "redirects" value changed to [
  { from: '/_next/static/*', to: '/static/:splat', status: 200 },
  {
    from: '/_next/image*',
    query: { url: ':url', w: ':width', q: ':quality' },
    to: '/_ipx/w_:width,q_:quality/:url',
    status: 301
  },
  { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
  { from: '/cache/*', to: '/404.html', status: 404, force: true },
  { from: '/server/*', to: '/404.html', status: 404, force: true },
  { from: '/serverless/*', to: '/404.html', status: 404, force: true },
  { from: '/trace', to: '/404.html', status: 404, force: true },
  { from: '/traces', to: '/404.html', status: 404, force: true },
  {
    from: '/routes-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  {
    from: '/build-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  {
    from: '/prerender-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  {
    from: '/react-loadable-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  { from: '/BUILD_ID', to: '/404.html', status: 404, force: true },
  {
    from: '/api/*',
    to: '/.netlify/functions/___netlify-handler',
    status: 200
  },
  {
    from: '/locales/fr/common.json',
    to: '/locales/fr/common.json',
    conditions: { Cookie: [Array] },
    status: 200
  },
  {
    from: '/*',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    conditions: { Cookie: [Array] },
    force: true
  },
  {
    from: '/_next/data/lpFTa_0ZbYxvBdGfG29qK/index.json',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/_next/data/lpFTa_0ZbYxvBdGfG29qK/login.json',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/login',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/_next/data/lpFTa_0ZbYxvBdGfG29qK/logout.json',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/logout',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/_next/data/lpFTa_0ZbYxvBdGfG29qK/challenge/:challengeId.json',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/challenge/:challengeId',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/_next/data/lpFTa_0ZbYxvBdGfG29qK/challenge/:challengeId/rankings.json',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/challenge/:challengeId/rankings',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/*',
    to: '/.netlify/functions/___netlify-handler',
    status: 200
  }
].
​
(@netlify/plugin-nextjs onBuild completed in 1s)
​
  4. Functions bundling                                         
────────────────────────────────────────────────────────────────
​
Packaging Functions from .netlify/functions-internal directory:
 - ___netlify-handler/___netlify-handler.js
 - ___netlify-odb-handler/___netlify-odb-handler.js
 - _ipx/_ipx.js
​
​
(Functions bundling completed in 56.9s)
​
  5. Edge Functions bundling                                    
────────────────────────────────────────────────────────────────
​
Packaging Edge Functions from .netlify/edge-functions directory:
 - ipx
​
(Edge Functions bundling completed in 5.2s)
​
  6. @netlify/plugin-nextjs (onPostBuild event)                 
────────────────────────────────────────────────────────────────
​
Next.js cache saved.
​
(@netlify/plugin-nextjs onPostBuild completed in 922ms)
​
  Netlify Build Complete                                        
────────────────────────────────────────────────────────────────
​
(Netlify Build completed in 3m 18.8s)
Deploy path:        /builds/ouigroup/client-dashboard/dist/apps/front/.next
Configuration path: /builds/ouigroup/client-dashboard/netlify.toml
Deploying to draft URL...
- Hashing files...
- Looking for a functions cache...
✔ Deploying functions from cache (use --skip-functions-cache to override)
✔ Finished hashing 77 files, 3 functions and edge functions
- CDN diffing files...
✔ CDN requesting 16 files and 3 functions
- Uploading 20 files
✔ Finished uploading 20 assets
- Waiting for deploy to go live...
✔ Deploy is live!
Logs:              https://app.netlify.com/sites/ouigroup-client-dashboard-stg/deploys/63da54d25327860b4f9d2ef6
Website Draft URL: https://dev--ouigroup-client-dashboard-stg.netlify.app
If everything looks good on your draft URL, deploy it to your main site URL with the --prod flag.
netlify deploy --build --prod
Saving cache for successful job
Creating cache 0-64be85f1fc9d4d8946bb4722756eb32241d3ad50-non_protected...
.yarn-cache/: found 111392 matching files and directories 
Uploading cache.zip to [xxx]
Created cache
Uploading artifacts for successful job
00:10
Uploading artifacts...
node_modules/.cache/nx: found 118 matching files and directories 
Uploading artifacts as "archive" to coordinator... 201 Created  id=3696200355 responseStatus=201 Created token=64_DyWmn
Cleaning up project directory and file based variables
00:01
Job succeeded

And I get the following error :

Error - Could not find a production build in the '/builds/ouigroup/client-dashboard/dist/apps/front-nextjs/.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id

Tried it, but the problem remain.

Do you think it’s possible to share your repo?

We’ve seen this happen with 2 other users but haven’t been able to reproduce the issue ourselves. So, a reproduction would help the devs make progress.

Hello,

I have the exact same issue. I tried using @netlify/plugin-nextjs version 4.25, --skip-nx-cache and no luck.

My build command is this

pnpm install && nx build package-name --skip-nx-cache && bash script.sh

pnpm install and nx build package-name run successfully. My script.sh will just print some information about the directories.

This is the output of ls -la dist/apps/app-name

2:42:34 PM: drwxr-xr-x 3 buildbot buildbot   29 Feb  6 12:41 ..
2:42:34 PM: drwxr-xr-x 6 buildbot buildbot 4096 Feb  6 12:42 .next
2:42:34 PM: -rw-r--r-- 1 buildbot buildbot  531 Feb  6 12:42 next.config.js
2:42:34 PM: drwxr-xr-x 2 buildbot buildbot   69 Feb  6 12:42 .nx-helpers
2:42:34 PM: -rw-r--r-- 1 buildbot buildbot  992 Feb  6 12:42 package.json
2:42:34 PM: drwxr-xr-x 5 buildbot buildbot   52 Feb  6 12:42 public

Yet the exact next build command complains

2:42:36 PM: Plugin "@netlify/plugin-nextjs" failed                        
2:42:36 PM: ────────────────────────────────────────────────────────────────
2:42:36 PM: ​
2:42:36 PM:   Error message
2:42:36 PM:   Error: The directory "/opt/build/repo/dist/apps/app-name" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.

Any ideas? I checked inside .next, and everything is built for production

I managed to solve my problem. If it’s not clear enough, the publish directory has to include the .next path. So I just updated my publish directory to dist/apps/app-name/.next (with the latest next.js plugin) and it worked!

thank you for sharing your solution! This is definitely helpful for other users :+1:t6: