Some of the routes in our Next.js applications throw a 500 Internal Server Error even when they exist and work in development mode.
Link - Playground | Crio.Do | Build internship-grade projects in a real developer environment and accelerate your full stack or backend developer career with a job-ready project portfolio. Enroll and start for free.
If I visit the above link via some other link like our homepage or so (client side routing), then it opens up fine. But when I hit the URL directly, it fails.
Points to note:
- We donβt do SSG or SSR on any of our pages. Itβs a plain vanilla next.js application.
- We donβt have any custom netlify functions.
- netlify.toml
[build]
command = "yarn run build"
publish = ".next"
[[plugins]]
package = "@netlify/plugin-nextjs"
yarn run build is basically next build
4. next.config.js
const path = require('path');
const withOptimizedImages = require('next-optimized-images');
const { withSentryConfig } = require('@sentry/nextjs');
const isProd = process.env.NODE_ENV === 'production';
const { withPlaiceholder } = require('@plaiceholder/next');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const moduleExports = withBundleAnalyzer(
withOptimizedImages(
withPlaiceholder({
images: {
disableStaticImages: true,
},
trailingSlash: true,
basePath: "learn/v2",
assetPrefix: "learn/v2",
publicRuntimeConfig: {
staticFolder: "learn/v2",
},
optimizeImagesInDev: true,
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
},
experimental: {
removeConsole: isProd ? true : false,
},
}),
),
);
const SentryWebpackPluginOptions = {
silent: true, // Suppresses all logs
};
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
- Deploy logs
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Netlify Build
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β― Version
@netlify/build 26.2.3
β― Flags
{}
β― Current directory
stage-crio
β― Config file
stage-crio/netlify.toml
β― Context
production
β― Loading plugins
- @netlify/plugin-nextjs@4.2.3 from netlify.toml and package.json
β― Outdated plugins
- @netlify/plugin-nextjs@4.2.3: latest version is 4.2.5
Migration guide: https://ntl.fyi/next-plugin-migration
To upgrade this plugin, please update its version in "package.json"
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. @netlify/plugin-nextjs (onPreBuild event)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Next.js cache restored.
Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
(@netlify/plugin-nextjs onPreBuild completed in 1.6s)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
2. build.command from netlify.toml
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$ yarn run build
yarn run v1.22.17
$ yarn startup
$ node startup.js
$ next build
warn - You have enabled experimental feature(s).
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.
info - Checking validity of types
info - Collecting page data
info - Generating static pages (26/26)
info - Finalizing page optimization
Page Size First Load JS
β β / 794 B 379 kB
β /_app 0 B 378 kB
β β /404 (387 ms) 5.19 kB 386 kB
β β /activities 75.4 kB 650 kB
β β /impersonate/[id] 462 B 441 kB
β β /login 5.4 kB 386 kB
β β /magic/[id] (385 ms) 46.8 kB 641 kB
β β /me/[meId] 2.39 kB 766 kB 252 B
β β /PSDS/playground (637 ms) 12.1 kB 12.3 kB 465 kB
+ First Load JS shared by all 378 kB
β chunks/framework-eeba1b405d308ec4.js 42.3 kB
β chunks/main-53e0cba5d7770f8c.js 26.8 kB
β chunks/pages/_app-3b8b53267a8228ec.js 306 kB
β chunks/webpack-4f6506a321871006.js 2.75 kB
β css/77e7be7280b21608.css 11.6 kB
β (Static) automatically rendered as static HTML (uses no initial props)
β¨ Done in 141.64s.
(build.command completed in 2m 21.8s)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
3. @netlify/plugin-nextjs (onBuild event)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Patching undefined
Moving static page files to serve from CDN...
Moved 5 files
Netlify configuration property "redirects" value changed to [
{
from: '/learn/v2/_next/static/*',
to: '/static/:splat',
status: 200
},
{
from: '/_next/image/*',
query: { url: ':url', w: ':width', q: ':quality' },
to: '/learn/v2/_ipx/w_:width,q_:quality/:url',
status: 301
},
{
from: '/learn/v2/_ipx/*',
to: '/.netlify/builders/_ipx',
status: 200
},
{
from: '/_next/static/image/*',
to: '/static/image/:splat',
status: 200
},
{
from: '/learn/v2/cache/*',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/server/*',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/serverless/*',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/traces',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/routes-manifest.json',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/build-manifest.json',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/prerender-manifest.json',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/react-loadable-manifest.json',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/BUILD_ID',
to: '/404.html',
status: 404,
force: true
},
{
from: '/learn/v2/api',
to: '/.netlify/functions/___netlify-handler',
status: 200
},
{
from: '/learn/v2/api/*',
to: '/.netlify/functions/___netlify-handler',
status: 200
},
{
from: '/learn/v2/favicon.ico',
to: '/learn/v2/favicon.ico',
conditions: { Cookie: [Array] },
status: 200
},
{
from: '/learn/v2/login-banner-desktop.png',
to: '/learn/v2/login-banner-desktop.png',
conditions: { Cookie: [Array] },
status: 200
},
{
from: '/learn/v2/login-banner-mobile.png',
to: '/learn/v2/login-banner-mobile.png',
conditions: { Cookie: [Array] },
status: 200
},
{
from: '/learn/v2/robots.txt',
to: '/learn/v2/robots.txt',
conditions: { Cookie: [Array] },
status: 200
},
{
from: '/learn/v2/vercel.svg',
to: '/learn/v2/vercel.svg',
conditions: { Cookie: [Array] },
status: 200
},
{
from: '/learn/v2/images/doodle-white.png',
to: '/learn/v2/images/doodle-white.png',
conditions: { Cookie: [Array] },
status: 200
},
{
from: '/learn/v2/*',
to: '/.netlify/functions/___netlify-handler',
status: 200,
conditions: { Cookie: [Array] },
force: true
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/index.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/404.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/404',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/PSDS/playground.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/PSDS/playground',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/activities.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/activities',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/login.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/login',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/not-found.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/not-found',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/impersonate/:id.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/impersonate/:id',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/_next/data/CBfHwQcumAqF7u6SOF_9j/magic/:id.json',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/magic/:id',
to: '/.netlify/functions/___netlify-handler',
status: 200,
force: false
},
{
from: '/learn/v2/*',
to: '/.netlify/functions/___netlify-handler',
status: 200
}
].
(@netlify/plugin-nextjs onBuild completed in 777ms)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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
No Functions were found in netlify/functions directory
(Functions bundling completed in 1m 31.7s)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
5. @netlify/plugin-nextjs (onPostBuild event)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Next.js cache saved.
(@netlify/plugin-nextjs onPostBuild completed in 1s)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Netlify Build Complete
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
(Netlify Build completed in 3m 59s)
Iβm afraid sharing repo might not be feasible, but I am open to share any info that you may require in order to help us resolve