Error 500 when fetching translations in `getServerSideProps`

Working on a NextJS website using next-i18next for translations. When fetching the locale files in getStaticProps (like shown here) it works fine but when I use getServerSideProps it returns error 500. According to the documentation it should also work with getServerSideProps.

It works locally when starting the website with netlify dev, fails only when deployed to Netlify.

Site name: iamsterdam-greenberry.netlify.app
Build log:

2:05:02 PM: Build ready to start
2:05:29 PM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
2:05:29 PM: build-image tag: v4.8.0
2:05:29 PM: buildbot version: e552b142336b2b1222a93a4fd4cbed0019c77b46
2:05:29 PM: Building without cache
2:05:29 PM: Starting to prepare the repo for build
2:05:29 PM: No cached dependencies found. Cloning fresh repo
2:05:29 PM: git clone git@gitlab.com:greenberrynl/amsterdam-en-partners/iamsterdam-website
2:05:30 PM: Preparing Git Reference refs/heads/development
2:05:31 PM: Parsing package.json dependencies
2:05:32 PM: Starting build script
2:05:32 PM: Installing dependencies
2:05:32 PM: Python version set to 2.7
2:05:32 PM: v16.14.2 is already installed.
2:05:33 PM: Now using node v16.14.2 (npm v8.5.0)
2:05:33 PM: Started restoring cached build plugins
2:05:33 PM: Finished restoring cached build plugins
2:05:33 PM: Attempting ruby version 2.7.2, read from environment
2:05:34 PM: Using ruby version 2.7.2
2:05:34 PM: Using PHP version 8.0
2:05:35 PM: No npm workspaces detected
2:05:35 PM: Started restoring cached node modules
2:05:35 PM: Finished restoring cached node modules
2:05:35 PM: Installing NPM modules using NPM version 8.5.0
2:05:36 PM: npm WARN EBADENGINE Unsupported engine {
2:05:36 PM: npm WARN EBADENGINE   package: 'iamsterdam-website@0.1.0',
2:05:36 PM: npm WARN EBADENGINE   required: { node: '16.14.0' },
2:05:36 PM: npm WARN EBADENGINE   current: { node: 'v16.14.2', npm: '8.5.0' }
2:05:36 PM: npm WARN EBADENGINE }
2:05:41 PM: npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
2:05:46 PM: > iamsterdam-website@0.1.0 prepare
2:05:46 PM: > husky install
2:05:46 PM: husky - Git hooks installed
2:05:46 PM: added 691 packages, and audited 692 packages in 11s
2:05:46 PM: 86 packages are looking for funding
2:05:46 PM:   run `npm fund` for details
2:05:46 PM: found 0 vulnerabilities
2:05:46 PM: NPM modules installed
2:05:47 PM: Started restoring cached go cache
2:05:47 PM: Finished restoring cached go cache
2:05:47 PM: go version go1.16.5 linux/amd64
2:05:47 PM: go version go1.16.5 linux/amd64
2:05:47 PM: Installing missing commands
2:05:47 PM: Verify run directory
2:05:48 PM: ​
2:05:48 PM: ────────────────────────────────────────────────────────────────
2:05:48 PM:   Netlify Build                                                 
2:05:48 PM: ────────────────────────────────────────────────────────────────
2:05:48 PM: ​
2:05:48 PM: ❯ Version
2:05:48 PM:   @netlify/build 26.5.2
2:05:48 PM: ​
2:05:48 PM: ❯ Flags
2:05:48 PM:   baseRelDir: true
2:05:48 PM:   buildId: 624d81eeeb210705dde96d6c
2:05:48 PM:   deployId: 624d81eeeb210705dde96d6e
2:05:48 PM: ​
2:05:48 PM: ❯ Current directory
2:05:48 PM:   /opt/build/repo
2:05:48 PM: ​
2:05:48 PM: ❯ Config file
2:05:48 PM:   No config file was defined: using default values.
2:05:48 PM: ​
2:05:48 PM: ❯ Context
2:05:48 PM:   branch-deploy
2:05:48 PM: ​
2:05:48 PM: ❯ Installing plugins
2:05:48 PM:    - @netlify/plugin-nextjs@4.2.8
2:06:00 PM: ​
2:06:00 PM: ❯ Loading plugins
2:06:00 PM:    - @netlify/plugin-nextjs@4.2.8 from Netlify app
2:06:02 PM: ​
2:06:02 PM: ────────────────────────────────────────────────────────────────
2:06:02 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
2:06:02 PM: ────────────────────────────────────────────────────────────────
2:06:02 PM: ​
2:06:02 PM: No Next.js cache to restore.
2:06:02 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
2:06:02 PM: ​
2:06:02 PM: (@netlify/plugin-nextjs onPreBuild completed in 28ms)
2:06:02 PM: ​
2:06:02 PM: ────────────────────────────────────────────────────────────────
2:06:02 PM:   2. Build command from Netlify app                             
2:06:02 PM: ────────────────────────────────────────────────────────────────
2:06:02 PM: ​
2:06:02 PM: $ npm run build
2:06:02 PM: > iamsterdam-website@0.1.0 build
2:06:02 PM: > next build
2:06:03 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2:06:03 PM: info  - Checking validity of types...
2:06:06 PM: info  - Creating an optimized production build...
2:06:06 PM: info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
2:06:07 PM: info  - Using external babel configuration from /opt/build/repo/.babelrc
2:06:23 PM: info  - Compiled successfully
2:06:23 PM: info  - Collecting page data...
2:06:27 PM: info  - Generating static pages (0/11)
2:06:27 PM: info  - Generating static pages (2/11)
2:06:27 PM: info  - Generating static pages (5/11)
2:06:27 PM: info  - Generating static pages (8/11)
2:06:27 PM: info  - Generating static pages (11/11)
2:06:27 PM: info  - Finalizing page optimization...
2:06:27 PM: Page                                       Size     First Load JS
2:06:27 PM: β”Œ ● /                                      2.33 kB        90.6 kB
2:06:27 PM: β”œ   β”” css/4d3314ff8e22b03f.css             81 B
2:06:27 PM: β”œ   /_app                                  0 B            88.3 kB
2:06:27 PM: β”œ β—‹ /404                                   2.84 kB        91.2 kB
2:06:27 PM: β”œ Ξ» /api/greeting                          0 B            88.3 kB
2:06:27 PM: β”œ β—‹ /design-system                         2.67 kB          91 kB
2:06:27 PM: β”œ   β”” css/cae9dac766f0af69.css             640 B
2:06:27 PM: β”œ Ξ» /posts                                 2.41 kB        90.7 kB
2:06:27 PM: β”” Ξ» /posts/[slug]                          2.35 kB        90.7 kB
2:06:27 PM: + First Load JS shared by all              88.3 kB
2:06:27 PM:   β”œ chunks/framework-5f4595e5518b5600.js   42 kB
2:06:27 PM:   β”œ chunks/main-e262eadf986b6d77.js        26.6 kB
2:06:27 PM:   β”œ chunks/pages/_app-3797ad3db40af4dc.js  18.2 kB
2:06:27 PM:   β”œ chunks/webpack-6fdf054321366d1c.js     1.52 kB
2:06:27 PM:   β”” css/3e8c2ed355a68dc4.css               119 B
2:06:27 PM: Ξ»  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
2:06:27 PM: β—‹  (Static)  automatically rendered as static HTML (uses no initial props)
2:06:27 PM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
2:06:27 PM: ​
2:06:27 PM: (build.command completed in 25.7s)
2:06:27 PM: ​
2:06:27 PM: ────────────────────────────────────────────────────────────────
2:06:27 PM:   3. @netlify/plugin-nextjs (onBuild event)                     
2:06:27 PM: ────────────────────────────────────────────────────────────────
2:06:27 PM: ​
2:06:27 PM: Patching /opt/build/repo/node_modules/next/dist/server/base-server.js
2:06:27 PM: Done
2:06:27 PM: Moving static page files to serve from CDN...
2:06:27 PM: Moved 6 files
2:06:27 PM: Netlify configuration property "redirects" value changed to [
2:06:27 PM:   { from: '/_next/static/*', to: '/static/:splat', status: 200 },
2:06:27 PM:   {
2:06:27 PM:     from: '/:locale/_next/static/*',
2:06:27 PM:     to: '/static/:splat',
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/image*',
2:06:27 PM:     query: { url: ':url', w: ':width', q: ':quality' },
2:06:27 PM:     to: '/_ipx/w_:width,q_:quality/:url',
2:06:27 PM:     status: 301
2:06:27 PM:   },
2:06:27 PM:   { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
2:06:27 PM:   { from: '/cache/*', to: '/404.html', status: 404, force: true },
2:06:27 PM:   { from: '/server/*', to: '/404.html', status: 404, force: true },
2:06:27 PM:   { from: '/serverless/*', to: '/404.html', status: 404, force: true },
2:06:27 PM:   { from: '/trace', to: '/404.html', status: 404, force: true },
2:06:27 PM:   { from: '/traces', to: '/404.html', status: 404, force: true },
2:06:27 PM:   {
2:06:27 PM:     from: '/routes-manifest.json',
2:06:27 PM:     to: '/404.html',
2:06:27 PM:     status: 404,
2:06:27 PM:     force: true
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/build-manifest.json',
2:06:27 PM:     to: '/404.html',
2:06:27 PM:     status: 404,
2:06:27 PM:     force: true
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/prerender-manifest.json',
2:06:27 PM:     to: '/404.html',
2:06:27 PM:     status: 404,
2:06:27 PM:     force: true
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/react-loadable-manifest.json',
2:06:27 PM:     to: '/404.html',
2:06:27 PM:     status: 404,
2:06:27 PM:     force: true
2:06:27 PM:   },
2:06:27 PM:   { from: '/BUILD_ID', to: '/404.html', status: 404, force: true },
2:06:27 PM:   {
2:06:27 PM:     from: '/',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: true,
2:06:27 PM:     conditions: { Cookie: [Array] }
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/',
2:06:27 PM:     to: '/nl-NL',
2:06:27 PM:     status: 301,
2:06:27 PM:     conditions: { Language: [Array] },
2:06:27 PM:     force: true
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/api',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/api/*',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/favicon.ico',
2:06:27 PM:     to: '/favicon.ico',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/fonts/roboto-v29-latin-regular.eot',
2:06:27 PM:     to: '/fonts/roboto-v29-latin-regular.eot',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/fonts/roboto-v29-latin-regular.svg',
2:06:27 PM:     to: '/fonts/roboto-v29-latin-regular.svg',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/fonts/roboto-v29-latin-regular.ttf',
2:06:27 PM:     to: '/fonts/roboto-v29-latin-regular.ttf',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/fonts/roboto-v29-latin-regular.woff',
2:06:27 PM:     to: '/fonts/roboto-v29-latin-regular.woff',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/fonts/roboto-v29-latin-regular.woff2',
2:06:27 PM:     to: '/fonts/roboto-v29-latin-regular.woff2',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/locales/en-US/common.json',
2:06:27 PM:     to: '/locales/en-US/common.json',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/locales/nl-NL/common.json',
2:06:27 PM:     to: '/locales/nl-NL/common.json',
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     status: 200
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/*',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     conditions: { Cookie: [Array] },
2:06:27 PM:     force: true
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/en-US/index.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/nl-NL/index.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/nl-NL/',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/en-US/design-system.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/design-system',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/nl-NL/design-system.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/nl-NL/design-system',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/en-US/posts.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/posts',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/nl-NL/posts.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/nl-NL/posts',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/en-US/posts/:slug.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/posts/:slug',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/_next/data/SCTjuOI_xfcyE0gDuR52b/nl-NL/posts/:slug.json',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/nl-NL/posts/:slug',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200,
2:06:27 PM:     force: false
2:06:27 PM:   },
2:06:27 PM:   {
2:06:27 PM:     from: '/*',
2:06:27 PM:     to: '/.netlify/functions/___netlify-handler',
2:06:27 PM:     status: 200
2:06:27 PM:   }
2:06:27 PM: ].
2:06:27 PM: ​
2:06:27 PM: (@netlify/plugin-nextjs onBuild completed in 82ms)
2:06:27 PM: ​
2:06:27 PM: ────────────────────────────────────────────────────────────────
2:06:27 PM:   4. Functions bundling                                         
2:06:27 PM: ────────────────────────────────────────────────────────────────
2:06:27 PM: ​
2:06:27 PM: Packaging Functions from .netlify/functions-internal directory:
2:06:27 PM:  - ___netlify-handler/___netlify-handler.js
2:06:27 PM:  - ___netlify-odb-handler/___netlify-odb-handler.js
2:06:27 PM:  - _ipx/_ipx.js
2:06:27 PM: ​
2:06:43 PM: ​
2:06:43 PM: (Functions bundling completed in 15.9s)
2:06:43 PM: ​
2:06:43 PM: ────────────────────────────────────────────────────────────────
2:06:43 PM:   5. @netlify/plugin-nextjs (onPostBuild event)                 
2:06:43 PM: ────────────────────────────────────────────────────────────────
2:06:43 PM: ​
2:06:43 PM: Next.js cache saved.
2:06:43 PM: ​
2:06:43 PM: (@netlify/plugin-nextjs onPostBuild completed in 167ms)
2:06:43 PM: ​
2:06:43 PM: ────────────────────────────────────────────────────────────────
2:06:43 PM:   6. Deploy site                                                
2:06:43 PM: ────────────────────────────────────────────────────────────────
2:06:43 PM: ​
2:06:44 PM: Creating deploy upload records
2:06:43 PM: Starting to deploy site from '.next'
2:06:44 PM: Creating deploy tree 
2:06:44 PM: 23 new files to upload
2:06:44 PM: 2 new functions to upload
2:06:52 PM: Site deploy was successfully initiated
2:06:52 PM: ​
2:06:52 PM: (Deploy site completed in 8s)
2:06:52 PM: ​
2:06:52 PM: ────────────────────────────────────────────────────────────────
2:06:52 PM:   Netlify Build Complete                                        
2:06:52 PM: Starting post processing
2:06:52 PM: ────────────────────────────────────────────────────────────────
2:06:52 PM: ​
2:06:52 PM: (Netlify Build completed in 1m 3.4s)
2:06:52 PM: Caching artifacts
2:06:52 PM: Started saving node modules
2:06:52 PM: Finished saving node modules
2:06:52 PM: Started saving build plugins
2:06:52 PM: Finished saving build plugins
2:06:52 PM: Post processing - HTML
2:06:52 PM: Started saving pip cache
2:06:52 PM: Finished saving pip cache
2:06:52 PM: Started saving emacs cask dependencies
2:06:52 PM: Finished saving emacs cask dependencies
2:06:52 PM: Started saving maven dependencies
2:06:52 PM: Finished saving maven dependencies
2:06:52 PM: Started saving boot dependencies
2:06:52 PM: Finished saving boot dependencies
2:06:52 PM: Started saving rust rustup cache
2:06:52 PM: Finished saving rust rustup cache
2:06:52 PM: Started saving go dependencies
2:06:52 PM: Finished saving go dependencies
2:06:53 PM: Build script success
2:06:54 PM: Post processing - header rules
2:06:54 PM: Post processing - redirect rules
2:06:54 PM: Post processing done
2:06:57 PM: Site is live ✨
2:07:21 PM: Finished processing build request in 1m52.108153842s

Hey there, @floris10hove :wave:

My apologies for the slow response here! Can you confirm if you are still encountering difficulties? If so, can you please share your project repo so that we can look into this further? Thank you so much!

Hi @hillary,

The problem still persists. I can’t share the original repo but could try to replicate it in a sandbox if that helps. In the meantime maybe you can use this as an example, but instead of using getStaticProps (as in the example) we want to use getServerSideProps in which case the site returns an error 500 when deployed to netlify.

Hey @floris10hove,

Sorry for the delay here. Could you try adding the following to your netlify.toml:

[functions]
  included_files = ["public/locales/*"]

Note that, you might have to change the directory path as that needs to be relative to the base path (the folder with package.json).

1 Like

This fixed it. Thnx.

1 Like

Thanks for letting us know! Happy building :rocket: