Error: Initial locale argument was not passed into serverSideTranslations
Environment:
next-i18next
- Next.js
- 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:
next.config.js
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 !