My Next.js build fails on Netlify with the message
The file “my-route/page.tsx” doesn’t have a root layout.
However, the root layout does exist (layout.tsx on the upper directory). This is how according to Next.js the app router should be set up.
The build successfully runs locally (using npm run build
with my local node version and even using buildbot from Netlify’s docker build-image (which obviously is kinda outdated, but still I tried it).
I am using
- nextjs 14.2.5
- node 20.15.1
- Netlify nextjs runtime 5.5.1
It is probably worth mentioning that while the route causing the error is not the only route, it is the only one that has another subroute with a dynamic parameter. The structure of my /app
folder looks somewhat like that:
/app
- my-route
- [slug]
- page.tsx
- page.tsx
- my-other-route
- page.tsx
- page.tsx
- layout.tsx
- not-found.tsx
How can I further debug my failing Netlify build and possibly reproduce the failing behaviour locally?
See the full initializing/build log here:
Initializing
12:53:56 PM: build-image version: 006dca901dab83234b4881f914ac1a189ff41daa (focal)
12:53:56 PM: buildbot version: 91afcc08587ca1ca63cf1aa8edb323949ceee060
12:53:56 PM: Fetching cached dependencies
12:53:56 PM: Failed to fetch cache, continuing with build
12:53:56 PM: Starting to prepare the repo for build
12:53:57 PM: No cached dependencies found. Cloning fresh repo
12:53:57 PM: git clone --filter=blob:none https://github.com/my-user/my-private-repo
12:53:57 PM: Preparing Git Reference refs/heads/production
12:53:59 PM: Starting to install dependencies
12:53:59 PM: Python version set to 3.8
12:53:59 PM: Attempting Ruby version 2.7.2, read from environment
12:54:00 PM: Using Ruby version 2.7.2
12:54:01 PM: Started restoring cached go cache
12:54:01 PM: Finished restoring cached go cache
12:54:02 PM: go version go1.19.13 linux/amd64
12:54:02 PM: Using PHP version 8.0
12:54:04 PM: Downloading and installing node v20.15.1...
12:54:04 PM: Downloading https://nodejs.org/dist/v20.15.1/node-v20.15.1-linux-x64.tar.xz...
12:54:04 PM: Computing checksum with sha256sum
12:54:05 PM: Checksums matched!
12:54:07 PM: Now using node v20.15.1 (npm v10.7.0)
12:54:07 PM: Enabling Node.js Corepack
12:54:07 PM: Started restoring cached build plugins
12:54:07 PM: Finished restoring cached build plugins
12:54:07 PM: Started restoring cached corepack dependencies
12:54:07 PM: Finished restoring cached corepack dependencies
12:54:07 PM: No npm workspaces detected
12:54:07 PM: Started restoring cached node modules
12:54:07 PM: Finished restoring cached node modules
12:54:07 PM: Installing npm packages using npm version 10.7.0
12:54:08 PM: npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
12:54:08 PM: npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
12:54:08 PM: npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
12:54:10 PM: npm warn deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
12:54:10 PM: npm warn deprecated @humanwhocodes/config-array@0.11.14: Use @eslint/config-array instead
12:54:16 PM: added 557 packages, and audited 558 packages in 9s
12:54:16 PM: 169 packages are looking for funding
12:54:16 PM: run `npm fund` for details
12:54:16 PM: found 0 vulnerabilities
12:54:16 PM: npm packages installed
12:54:16 PM: Successfully installed dependencies
12:54:16 PM: Starting build script
12:54:17 PM: Detected 1 framework(s)
12:54:17 PM: "next" at version "14.2.5"
12:54:17 PM: Section completed: initializing
Summary
12:54:19 PM: Netlify Build
12:54:19 PM: ────────────────────────────────────────────────────────────────
12:54:19 PM:
12:54:19 PM: ❯ Version
12:54:19 PM: @netlify/build 29.51.3
12:54:19 PM:
12:54:19 PM: ❯ Flags
12:54:19 PM: baseRelDir: true
12:54:19 PM: buildId: 6698f43aeab6230008f2a6cf
12:54:19 PM: deployId: 6698f43aeab6230008f2a6d1
12:54:19 PM:
12:54:19 PM: ❯ Current directory
12:54:19 PM: /opt/build/repo
12:54:19 PM:
12:54:19 PM: ❯ Config file
12:54:19 PM: No config file was defined: using default values.
12:54:19 PM:
12:54:19 PM: ❯ Context
12:54:19 PM: production
12:54:20 PM:
12:54:20 PM: ❯ Using Next.js Runtime - v5.5.1
12:54:21 PM: No Next.js cache to restore
12:54:21 PM:
12:54:21 PM: Build command from Netlify app
12:54:21 PM: ────────────────────────────────────────────────────────────────
12:54:21 PM:
12:54:21 PM: $ npm run build
12:54:21 PM: > my-page@0.0.1 build
12:54:21 PM: > next build
12:54:21 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
12:54:21 PM: ▲ Next.js 14.2.5
12:54:21 PM: Creating an optimized production build ...
12:54:22 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
12:54:22 PM: ⨯ my-route/page.tsx doesn't have a root layout. To fix this error, make sure every page has a root layout.
12:54:22 PM: "build.command" failed
12:54:22 PM: ────────────────────────────────────────────────────────────────
12:54:22 PM:
12:54:22 PM: Error message
12:54:22 PM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
12:54:22 PM:
12:54:22 PM: Error location
12:54:22 PM: In Build command from Netlify app:
12:54:22 PM: npm run build
12:54:22 PM:
12:54:22 PM: Resolved config
12:54:22 PM: build:
12:54:22 PM: command: npm run build
12:54:22 PM: commandOrigin: ui
12:54:22 PM: publish: /opt/build/repo/.next
12:54:22 PM: publishOrigin: ui
12:54:22 PM: plugins:
12:54:22 PM: - inputs: {}
12:54:22 PM: origin: ui
12:54:22 PM: package: '@netlify/plugin-nextjs'
12:54:22 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:54:22 PM: Failing build: Failed to build site
12:54:23 PM: Finished processing build request in 26.702s
Edit: I forgot to mention that there are no non-default environment variables involved in the build that could be missing while building locally, at least not any that I know of. NODE_ENV
and NODE_VERSION
have been set to match Netlify’s build environment and I am not using any custom env variables.