Cannot get my next.js app to deploy correctly

Hello all,

Before asking for help I looked through the forums and tried multiple solutions to no avail. My issue is my next App is not deploying correctly. The deployment runs successfully but when I go to the URL I get β€œpage not found”

My Next.config.js file looks like this:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  distDir: "build",
  target: "serverless",
};

module.exports = nextConfig;

My netlify.toml file:

[build]
  command = "npm run build && npm run export"
  publish = "/build"
  base ="/"

Package.json:

"scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "export": "next export"
  },
  "dependencies": {
    "next": "12.2.2",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },

The production build is this:

7:27:57 PM: Build ready to start
7:28:06 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
7:28:06 PM: build-image tag: v4.10.1
7:28:06 PM: buildbot version: 4cffa5dc84445a450e8be6f710e2498d87994fae
7:28:06 PM: Fetching cached dependencies
7:28:07 PM: Starting to download cache of 593.0MB
7:28:11 PM: Finished downloading cache in 4.015042702s
7:28:11 PM: Starting to extract cache
7:28:13 PM: Finished extracting cache in 2.790223838s
7:28:13 PM: Finished fetching cache in 6.909305826s
7:28:13 PM: Starting to prepare the repo for build
7:28:14 PM: Preparing Git Reference refs/heads/main
7:28:15 PM: Parsing package.json dependencies
7:28:16 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: '' versus '/build' in the Netlify UI
7:28:16 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'build' versus '' in the Netlify UI
7:28:16 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'npm run build && npm run export' versus 'npm run build' in the Netlify UI
7:28:16 PM: Starting build script
7:28:16 PM: Installing dependencies
7:28:16 PM: Python version set to 2.7
7:28:16 PM: Started restoring cached node version
7:28:17 PM: Finished restoring cached node version
7:28:18 PM: v16.17.0 is already installed.
7:28:18 PM: Now using node v16.17.0 (npm v8.15.0)
7:28:18 PM: Started restoring cached build plugins
7:28:18 PM: Finished restoring cached build plugins
7:28:18 PM: Attempting ruby version 2.7.2, read from environment
7:28:19 PM: Using ruby version 2.7.2
7:28:19 PM: Using PHP version 8.0
7:28:19 PM: Started restoring cached yarn cache
7:28:20 PM: Finished restoring cached yarn cache
7:28:20 PM: No yarn workspaces detected
7:28:20 PM: Started restoring cached node modules
7:28:20 PM: Finished restoring cached node modules
7:28:20 PM: Installing NPM modules using Yarn version 1.22.10
7:28:21 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
7:28:21 PM: npm WARN config location in the cache, and they are managed by
7:28:21 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
7:28:21 PM: yarn install v1.22.10
7:28:21 PM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
7:28:21 PM: [1/4] Resolving packages...
7:28:22 PM: [2/4] Fetching packages...
7:28:22 PM: info @next/swc-darwin-arm64@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-darwin-arm64@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-darwin-arm64@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: info @next/swc-linux-arm64-gnu@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: info "@next/swc-linux-arm64-gnu@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-linux-arm-gnueabihf@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: info "@next/swc-linux-arm-gnueabihf@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-linux-arm64-musl@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: info "@next/swc-linux-arm64-musl@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-android-arm64@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-android-arm64@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-android-arm64@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: info @next/swc-darwin-x64@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-darwin-x64@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-win32-arm64-msvc@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-win32-arm64-msvc@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-win32-arm64-msvc@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: info @next/swc-win32-x64-msvc@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-win32-x64-msvc@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-win32-ia32-msvc@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-win32-ia32-msvc@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-win32-ia32-msvc@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: info @next/swc-freebsd-x64@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-freebsd-x64@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-android-arm-eabi@12.2.2: The platform "linux" is incompatible with this module.
7:28:22 PM: info "@next/swc-android-arm-eabi@12.2.2" is an optional dependency and failed compatibility check. Excluding it from installation.
7:28:22 PM: info @next/swc-android-arm-eabi@12.2.2: The CPU architecture "x64" is incompatible with this module.
7:28:22 PM: [3/4] Linking dependencies...
7:28:22 PM: [4/4] Building fresh packages...
7:28:22 PM: success Saved lockfile.
7:28:22 PM: Done in 1.55s.
7:28:22 PM: NPM modules installed using Yarn
7:28:23 PM: Started restoring cached go cache
7:28:23 PM: Finished restoring cached go cache
7:28:23 PM: Installing Go version 1.16.5 (requested 1.16.5)
7:28:27 PM: unset GOOS;
7:28:27 PM: unset GOARCH;
7:28:27 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.16.5.linux.amd64';
7:28:27 PM: export PATH="/opt/buildhome/.gimme/versions/go1.16.5.linux.amd64/bin:${PATH}";
7:28:27 PM: go version >&2;
7:28:27 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.16.5.linux.amd64.env"
7:28:27 PM: go version go1.16.5 linux/amd64
7:28:27 PM: Installing missing commands
7:28:27 PM: Verify run directory
7:28:28 PM: ​
7:28:28 PM: ────────────────────────────────────────────────────────────────
7:28:28 PM:   Netlify Build                                                 
7:28:28 PM: ────────────────────────────────────────────────────────────────
7:28:28 PM: ​
7:28:28 PM: ❯ Version
7:28:28 PM:   @netlify/build 27.11.5
7:28:28 PM: ​
7:28:28 PM: ❯ Flags
7:28:28 PM:   baseRelDir: true
7:28:28 PM:   buildId: 62fd797d2855950008dccbc6
7:28:28 PM:   deployId: 62fd797d2855950008dccbc8
7:28:28 PM: ​
7:28:28 PM: ❯ Current directory
7:28:28 PM:   /opt/build/repo
7:28:28 PM: ​
7:28:28 PM: ❯ Config file
7:28:28 PM:   /opt/build/repo/netlify.toml
7:28:28 PM: ​
7:28:28 PM: ❯ Context
7:28:28 PM:   production
7:28:28 PM: ​
7:28:28 PM: ────────────────────────────────────────────────────────────────
7:28:28 PM:   1. build.command from netlify.toml                            
7:28:28 PM: ────────────────────────────────────────────────────────────────
7:28:28 PM: ​
7:28:28 PM: $ npm run build && npm run export
7:28:28 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
7:28:28 PM: npm WARN config location in the cache, and they are managed by
7:28:28 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
7:28:28 PM: > japan-cc@0.1.0 build
7:28:28 PM: > next build
7:28:28 PM: warn  - The `target` config is deprecated and will be removed in a future version.
7:28:28 PM: See more info here https://nextjs.org/docs/messages/deprecated-target-config
7:28:28 PM: info  - SWC minify release candidate enabled. https://nextjs.link/swcmin
7:28:28 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
7:28:28 PM: info  - Linting and checking validity of types...
7:28:30 PM: ./pages/course.tsx
7:28:30 PM: 43:9  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 43:9  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: ./pages/courses.tsx
7:28:30 PM: 32:9  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 32:9  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: 38:13  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 38:13  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: 53:15  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 53:15  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: ./components/Body/index.tsx
7:28:30 PM: 56:7  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 56:7  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: ./components/Courses/index.tsx
7:28:30 PM: 20:7  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 20:7  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: ./components/Footer/index.tsx
7:28:30 PM: 32:9  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 32:9  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: ./components/Posts/index.tsx
7:28:30 PM: 22:7  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 22:7  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: ./components/Reviews/index.tsx
7:28:30 PM: 16:15  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 16:15  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: 23:17  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 23:17  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: ./components/Staff/index.tsx
7:28:30 PM: 46:11  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 46:11  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: 76:17  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
7:28:30 PM: 76:17  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
7:28:30 PM: info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
7:28:31 PM: info  - Creating an optimized production build...
7:28:35 PM: info  - Compiled successfully
7:28:35 PM: info  - Collecting page data...
7:28:37 PM: info  - Generating static pages (0/6)
7:28:38 PM: info  - Generating static pages (1/6)
7:28:38 PM: info  - Generating static pages (2/6)
7:28:38 PM: info  - Generating static pages (4/6)
7:28:38 PM: info  - Generating static pages (6/6)
7:28:38 PM: info  - Finalizing page optimization...
7:28:38 PM: Page                                       Size     First Load JS
7:28:38 PM: β”Œ β—‹ / (312 ms)                             3.65 kB        81.9 kB
7:28:38 PM: β”œ   β”” css/4c389932d785ffa0.css             1.52 kB
7:28:38 PM: β”œ   /_app                                  0 B            78.3 kB
7:28:38 PM: β”œ β—‹ /404                                   186 B          78.5 kB
7:28:38 PM: β”œ β—‹ /boarding (312 ms)                     3.21 kB        81.5 kB
7:28:38 PM: β”œ   β”” css/853d53fd108c77df.css             732 B
7:28:38 PM: β”œ β—‹ /course (315 ms)                       3.67 kB        81.9 kB
7:28:38 PM: β”œ   β”” css/76bc6e24d4388017.css             781 B
7:28:38 PM: β”” β—‹ /courses                               3.03 kB        81.3 kB
7:28:38 PM:     β”” css/8263c09a877f357b.css             980 B
7:28:38 PM: + First Load JS shared by all              78.3 kB
7:28:38 PM:   β”œ chunks/framework-ae4f43955bfa5ddc.js   45.7 kB
7:28:38 PM:   β”œ chunks/main-3cf1b4d0a841b0b4.js        31.1 kB
7:28:38 PM:   β”œ chunks/pages/_app-0b9fa9d238e133c7.js  662 B
7:28:38 PM:   β”œ chunks/webpack-34c76af51fb9f015.js     760 B
7:28:38 PM:   β”” css/c46d95ee57f08382.css               148 B
7:28:38 PM: β—‹  (Static)  automatically rendered as static HTML (uses no initial props)
7:28:38 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
7:28:38 PM: npm WARN config location in the cache, and they are managed by
7:28:38 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
7:28:38 PM: > japan-cc@0.1.0 export
7:28:38 PM: > next export
7:28:39 PM: warn  - The `target` config is deprecated and will be removed in a future version.
7:28:39 PM: See more info here https://nextjs.org/docs/messages/deprecated-target-config
7:28:39 PM: info  - SWC minify release candidate enabled. https://nextjs.link/swcmin
7:28:39 PM: info  - using build directory: /opt/build/repo/build
7:28:39 PM: info  - Copying "static build" directory
7:28:39 PM: info  - No "exportPathMap" found in "/opt/build/repo/next.config.js". Generating map from "./pages"
7:28:39 PM: info  - Launching 31 workers
7:28:39 PM: info  - Exporting (0/6)
7:28:39 PM: info  - Copying "public" directory
7:28:39 PM: info  - Exporting (1/6)
7:28:39 PM: info  - Exporting (2/6)
7:28:39 PM: info  - Exporting (4/6)
7:28:40 PM: Creating deploy upload records
7:28:39 PM: info  - Exporting (6/6)
7:28:40 PM: Export successful. Files written to /opt/build/repo/out
7:28:40 PM: ​
7:28:40 PM: (build.command completed in 12s)
7:28:40 PM: ​
7:28:40 PM: ────────────────────────────────────────────────────────────────
7:28:40 PM:   2. Deploy site                                                
7:28:40 PM: ────────────────────────────────────────────────────────────────
7:28:40 PM: ​
7:28:40 PM: Starting to deploy site from 'build'
7:28:40 PM: Creating deploy tree 
7:28:40 PM: 18 new files to upload
7:28:40 PM: 0 new functions to upload
7:28:41 PM: Site deploy was successfully initiated
7:28:41 PM: ​
7:28:41 PM: (Deploy site completed in 740ms)
7:28:41 PM: ​
7:28:41 PM: Starting post processing
7:28:41 PM: ────────────────────────────────────────────────────────────────
7:28:41 PM:   Netlify Build Complete                                        
7:28:41 PM: ────────────────────────────────────────────────────────────────
7:28:41 PM: ​
7:28:41 PM: Post processing - HTML
7:28:41 PM: (Netlify Build completed in 12.8s)
7:28:41 PM: Caching artifacts
7:28:41 PM: Started saving node modules
7:28:41 PM: Finished saving node modules
7:28:41 PM: Started saving build plugins
7:28:41 PM: Finished saving build plugins
7:28:41 PM: Started saving yarn cache
7:28:41 PM: Post processing - header rules
7:28:41 PM: Post processing - redirect rules
7:28:42 PM: Post processing done
7:28:42 PM: Finished saving yarn cache
7:28:42 PM: Started saving pip cache
7:28:42 PM: Finished saving pip cache
7:28:42 PM: Started saving emacs cask dependencies
7:28:42 PM: Finished saving emacs cask dependencies
7:28:42 PM: Started saving maven dependencies
7:28:42 PM: Finished saving maven dependencies
7:28:42 PM: Started saving boot dependencies
7:28:42 PM: Finished saving boot dependencies
7:28:42 PM: Started saving rust rustup cache
7:28:42 PM: Finished saving rust rustup cache
7:28:42 PM: Started saving go dependencies
7:28:42 PM: Finished saving go dependencies
7:28:42 PM: Build script success
7:28:44 PM: Site is live ✨
7:28:44 PM: Uploading Cache of size 593.4MB
7:28:48 PM: Finished processing build request in 41.972297048s

Thank you so much for helping me with this. I’m not sure what I’m doing wrong.

Hey @Louis345

Under the next export logs I see

and then see

So the build is written to build, the export to out.

Then I see

Which means you are deploying the build (build) directory, not the out (export) directory.

1 Like

Hey there, @Louis345 :wave:

Thanks for reaching out, and welcome to the Netlify Forums! If @coelmay’s post doesn’t get you on the right track, please follow up with a link to your deployed site so that we can continue to investigate further.

I’m not sure how to resolve the issue you’re pointing out.

Perhaps change the publish directory to out instead of build.

Also note, base isn’t necessary when deploying from the root of the repository.

Thanks I will test it now

[build]
  command = "npm run build && npm run export"
  publish = "/out/repo/export"

The build error I get now is:

Base directory does not exist: /opt/build/repo/build```

Perhaps I might need the base entry?

JapancanCode.com it’s not working yet.

Can you share the repository you are deploying from?

Can you change this to

publish = "out"

thanks will try now. I appreciate all the help.

I’m still getting this error:

9:45:58 PM: Build ready to start
9:45:59 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
9:45:59 PM: build-image tag: v4.10.1
9:45:59 PM: buildbot version: 4cffa5dc84445a450e8be6f710e2498d87994fae
9:45:59 PM: Fetching cached dependencies
9:45:59 PM: Starting to download cache of 593.4MB
9:46:06 PM: Finished downloading cache in 6.181988763s
9:46:06 PM: Starting to extract cache
9:46:09 PM: Finished extracting cache in 3.70150058s
9:46:09 PM: Finished fetching cache in 9.97650616s
9:46:09 PM: Starting to prepare the repo for build
9:46:10 PM: Preparing Git Reference refs/heads/main
9:46:11 PM: Parsing package.json dependencies
9:46:11 PM: Creating deploy upload records
9:46:12 PM: Failing build: Failed to parse configuration
9:46:12 PM: Failed during stage 'Reading and parsing configuration files': When resolving config file /opt/build/repo/netlify.toml:Base directory does not exist: /opt/build/repo/build: exit status 1
9:46:12 PM: Finished processing build request in 12.576599884s

netlify.toml

  command = "npm run build && npm run export"
  publish = "out"

its not finding the build directory.

I resolved my issue. For anyone having trouble, this might help:

  publish = "out"
  base = "."

Thank you everyone for helping me.

2 Likes

Hey there, @Louis345 :wave:

Thank you so much for coming back and sharing your solution! It will definitely be beneficial for future Forums members who encounter something similar.