Error: Initial locale argument was not passed into serverSideTranslations

Environment:

  1. next-i18next
  2. Next.js
  3. Docker

Causes:

My code work in local so I blindly pack it with Docker and deploy … then boom this error is thrown.

I use the template Dockerfile from Next.js site.

...
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
...CMD ["yarn", "start"]

And it doesn’t copy next.config.js and next-i18next.config.js into the Docker image.

Initially, I though there is due to no env LANG or LC inside the docker, I inject the local but it doesn’t work.

It turns out that i18n library detect the language from these two files:

  1. next.config.js
  2. next-i18next.config.js

Solution:

Copy that two files into the Docker container too by adding these two line

COPY --from=builder /app/next.config.js ./next.config.js
COPY --from=builder /app/next-i18next.config.js ./next-i18next.config.js

Hope this helps !

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store