Error: Initial locale argument was not passed into serverSideTranslations

ReactJS Jun 30, 2023

Environment:

next-i18next

  1. Next.js
  2. 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 !

Tags

TeamCMD

We are CODEMONDAY team and provide a variety of content about Business , technology, and Programming. Let's enjoy it with us.