Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Missing locale files with next-i18next #169

Closed
2j2e opened this issue Feb 17, 2021 · 10 comments
Closed

Missing locale files with next-i18next #169

2j2e opened this issue Feb 17, 2021 · 10 comments
Labels
priority: high type: bug code to address defects in shipped code

Comments

@2j2e
Copy link

2j2e commented Feb 17, 2021

I'm running into an issue with next-i18next. Read all related issues, read the PR which should cover i18n issues, but still in a circle of fail.
{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, scandir '/var/task/public/static/locales/en'","trace":["Error: ENOENT: no such file or directory, scandir '/var/task/public/static/locales/en'"," at Object.readdirSync (fs.js:955:3)"," at getAllNamespaces (/var/task/src/netlify/functions/next_admin/nextPage.js:89104:21)"," at createConfig (/var/task/src/netlify/functions/next_admin/nextPage.js:89109:29)"," at new NextI18Next (/var/task/src/netlify/functions/next_admin/nextPage.js:119486:48)"," at Object.k7Sn (/var/task/src/netlify/functions/next_admin/nextPage.js:89904:18)"," at __webpack_require__ (/var/task/src/netlify/functions/next_admin/nextPage.js:31:31)"," at Module.cha2 (/var/task/src/netlify/functions/next_admin/nextPage.js:69840:63)"," at __webpack_require__ (/var/task/src/netlify/functions/next_admin/nextPage.js:31:31)"," at Module.kt/p (/var/task/src/netlify/functions/next_admin/nextPage.js:91877:22)"," at __webpack_require__ (/var/task/src/netlify/functions/next_admin/nextPage.js:31:31)"]}

To Reproduce
The whole configuration done according to docs.
i18n.js (next-i18next)

const NextI18Next = require('next-i18next').default
const { localeSubpaths } = require('next/config').default().publicRuntimeConfig
const path = require('path')

module.exports = new NextI18Next({
  defaultLanguage: 'en',
  otherLanguages: ['fr'],
  localeSubpaths,
  localePath: path.resolve('./public/static/locales'),
})

next.config.js

const { nextI18NextRewrites } = require('next-i18next/rewrites')
module.exports = {
    target: 'serverless',
    rewrites: async () => nextI18NextRewrites(localeSubpaths),
    publicRuntimeConfig: {
      localeSubpaths,
    },
    i18n: {
      defaultLocale: 'en',
      locales: ['en', 'fr'],
    },
  }
}

Versions

  • Next: 10.0.6
  • next-on-netlify: 2.0.0
@lindsaylevine
Copy link
Contributor

lindsaylevine commented Feb 17, 2021

hey @2j2e! thanks for bringing this to us! my first thought:

why are you using next-i18next along with the framework's embedded i18n support? aka, you have:

 i18n: {
      defaultLocale: 'en',
      locales: ['en', 'fr'],
    },

in your next.config.js

in next 10+, this configuration alone will take care out of i18n out of the box for you, with no need for an additional package like next-i18next. i believe packages like that one existed before next 10 was released with native i18n support.

@lindsaylevine
Copy link
Contributor

note: if you're using i18n in next 10.0.6, you need to be on next-on-netlify 2.8.7 per a breaking change in 10.0.6. see this release: https://github.com/netlify/next-on-netlify/releases/tag/v2.8.7

@2j2e
Copy link
Author

2j2e commented Feb 18, 2021

I tried with and without explicit next.config.js settings and it has zero effect. According to official Next.js docs the i18n support is only about proper routing, everything else should be done with external libraries.

The i18n routing support is currently meant to complement existing i18n library solutions like react-intl, react-i18next, lingui, rosetta, and others by streamlining the routes and locale parsing.

next-i18next built on top of react-i18next, so we should be good here.

if you're using i18n in next 10.0.6, you need to be on next-on-netlify 2.8.7 per a breaking change in 10.0.6.

According to my lock file, the plugin uses v2.8.7 under the hood.

"@netlify/plugin-nextjs@^2.0.0":
  version "2.0.0"
  resolved "https://registry.yarnpkg.com/@netlify/plugin-nextjs/-/plugin-nextjs-2.0.0.tgz#17a02a9ee68f9149dd604644a7006518320c8e9b"
  integrity sha512-vUAnMExD4FpjtxjO65NYzpzPgoIPCiNxXW9GIC9n5tuW5UUbdGRerSH9kqp5j75J89Ll/cVzUlZJpnSRxy5v0Q==
  dependencies:
    chalk "^4.1.0"
    find-up "^4.1.0"
    jimp "^0.16.1"
    make-dir "^3.1.0"
    next-on-netlify "2.8.7"
    semver "^7.3.2"

Looking on the pipeline next.js > next-i18next > netlify > netlify/plugin-nextjs I can think on 2 source of the issue.

  1. Next.js + next-i18next build is doing something wrong.
  2. Netlify + netlify/plugin-nextjs is doing something wrong.

I made a quick test with Vercel deployment and everything works fine, this means #1 is not an option for this case.

@lindsaylevine
Copy link
Contributor

@2j2e gotcha gotcha ok i'm with you!! thanks for explaining. let's see then what might be up. are you able to open a simple repo with next-i18next and the configs you've already shared that reproduces your issue? one thing i will say is that we don't currently support next-configured redirects and rewrites (see https://github.com/netlify/next-on-netlify/issues/24), but i think your existing issue is just related to your translations not being bundled with the lambda for whatever page you're trying to view (assuming the error you shared is at runtime).

@lindsaylevine lindsaylevine added type: bug code to address defects in shipped code priority: high labels Feb 19, 2021
@lindsaylevine
Copy link
Contributor

i believe this is related to https://github.com/netlify/next-on-netlify/issues/124

@2j2e
Copy link
Author

2j2e commented Feb 20, 2021

Not sure about #124,
Here is the example repo, a clone of the official next-i18next example combining with Netlify configuration.

@2j2e
Copy link
Author

2j2e commented Feb 20, 2021

Wooh, I found that next v10 is not actually supported by next-i18next, what a twist.

@lindsaylevine
Copy link
Contributor

@2j2e haaa oh no.. what does that mean exactly for you/for this issue?

i will say that i still believe this is at least in part related to #124 because it seems public/static/locales is not getting bundled with the netlify function for your pages/index.js, causing that error during "runtime"/from within the function environment. that, or somehow they are being bundled and just accessible at a different path. either way, it will depend on the work that will resolve #124, which is a high priority for us right now!

and again rewrites: async () => nextI18NextRewrites(localeSubpaths) - this won't be supported on netlify at the moment and so would probably cause its own issues (even if there was next 10 support for next-i18next).

all that said, is this specific issue something you want to keep open for when next 10 is supported by next-i18next? would you be comfortable tracking the other issues (#124, #24) that would be blockers for this type of integration?

let me know what you're thinking!

@2j2e
Copy link
Author

2j2e commented Feb 20, 2021

Thank you for a quick tracking and answers. I decided to switch to the next-translate. Not just decided, but already did and works perfect for now.
I don't know if you want to keep this issue open, but I'm OK to close it.

@lindsaylevine
Copy link
Contributor

@2j2e of course!!! and oh that's great news yay! i'll close this one and if you run into any issues with next-translate you can always open another! 🖖

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority: high type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants