next-i18next: Can't find i18n folder when deploying via @zeit/Now

Describe the bug

Tried to deploy examples/simple to now but failed to run.

Occurs in next-i18next version

V1.0.0

Steps to reproduce

  • clone examples/simple
  • deploy to now
  • 502: BAD_GATEWAY

Expected behaviour

it should run successfully on now platform

Screenshots

ERROR	Uncaught Exception	{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, scandir '/var/task/static/locales/en'","code":"ENOENT","stack":["Error: ENOENT: no such file or directory, scandir '/var/task/static/locales/en'","    at Object.readdirSync (fs.js:790:3)","    at getAllNamespaces (/var/task/page.js:14724:19)","    at _default (/var/task/page.js:14729:27)","    at new NextI18Next (/var/task/page.js:17983:46)","    at Object.k7Sn (/var/task/page.js:14791:18)","    at __webpack_require__ (/var/task/page.js:23:31)","    at Module.Y0NT (/var/task/page.js:9811:63)","    at __webpack_require__ (/var/task/page.js:23:31)","    at Module.f8ve (/var/task/page.js:11600:85)","    at __webpack_require__ (/var/task/page.js:23:31)"],"errno":-2,"syscall":"scandir","path":"/var/task/static/locales/en"}
END RequestId: ba58e4b2-1a15-46d6-9693-00b1206c6973
REPORT RequestId: ba58e4b2-1a15-46d6-9693-00b1206c6973	
Screenshot 2019-08-17 at 19 18 04 Screenshot 2019-08-17 at 19 18 39

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 15
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@samiulhsohan You need add the path of your locale files

// next-i18next.config.jjs
const path = require('path')

module.exports = {
  i18n: {
    defaultLocale: "en",
    locales: ["en", "fr"],
    localePath: path.resolve('./public/locales')
  },
};

Duplicate of #274.

@anialamo Check this repo. It’s deployed on Vercel here. Good luck!

Excuse me guys I probably have searched for every thread that is related to this but I can’t find a way to tell the server what is the path to the locales… I didn’t find anything helping me in the said duplicate #274.

I am also using vercel, did anyone manage to make it work with next-i18next ?

My locales are located in public/static/locales

But when I deploy I got this path as not found

/var/task/public/static/locales/en’

I noticed that once deployed the structure on vercel has no public/

Capture d’écran 2020-07-07 à 16 25 30

I know that “/public/static/locales” is the default i18n path, so I tried to change it to /static/locales so it will fit the vercel structure.

So I set localePath to “static/locales”

Then is does not deploy anymore and I got this as a path not found…

****/vercel/7d248d1f/static/locales/en’

I tried also the backEnd config option without success…

I am out of idea. Help 😢 Thank you guys.

@Chill-Studio did you found how to resolve this error? Can you help me please?

Excuse me guys I probably have searched for every thread that is related to this but I can’t find a way to tell the server what is the path to the locales… I didn’t find anything helping me in the said duplicate #274.

I am also using vercel, did anyone manage to make it work with next-i18next ?

My locales are located in public/static/locales

But when I deploy I got this path as not found

/var/task/public/static/locales/en’

I noticed that once deployed the structure on vercel has no public/

Capture d’écran 2020-07-07 à 16 25 30

I know that “/public/static/locales” is the default i18n path, so I tried to change it to /static/locales so it will fit the vercel structure.

So I set localePath to “static/locales”

Then is does not deploy anymore and I got this as a path not found…

****/vercel/7d248d1f/static/locales/en’

I tried also the backEnd config option without success…

I am out of idea. Help 😢 Thank you guys.

At the moment, the best “workaround” is to use a different serverless platform.

@samiulhsohan You need add the path of your locale files

// next-i18next.config.jjs
const path = require('path')

module.exports = {
  i18n: {
    defaultLocale: "en",
    locales: ["en", "fr"],
    localePath: path.resolve('./public/locales')
  },
};

I think this issue is back in recent versions (I’m on 13.2.2). I get a warning:

warn  - Invalid next.config.js options detected: 
warn  -     The value at .i18n has an unexpected property, localePath, which is not in the list of allowed properties (defaultLocale, domains, localeDetection, locales).
warn  - See more info here: https://nextjs.org/docs/messages/invalid-next-config

And it still works locally, but not in Vercel.

I think you need to move localePath into the exported module root scope:

module.exports = {
  i18n: {
    locales: ['de-CH', 'fr', 'en'],
    defaultLocale: 'de-CH',
    localeDetection: true,
  },
  localePath: path.resolve('./public/locales'),
  reloadOnPrerender: process.env.NODE_ENV === 'development',
}

Not sure where it’s documented but it worked for me.

here: https://github.com/i18next/next-i18next#vercel-and-netlify

@samiulhsohan You need add the path of your locale files

// next-i18next.config.jjs
const path = require('path')

module.exports = {
  i18n: {
    defaultLocale: "en",
    locales: ["en", "fr"],
    localePath: path.resolve('./public/locales')
  },
};

I think this issue is back in recent versions (I’m on 13.2.2). I get a warning:

warn  - Invalid next.config.js options detected: 
warn  -     The value at .i18n has an unexpected property, localePath, which is not in the list of allowed properties (defaultLocale, domains, localeDetection, locales).
warn  - See more info here: https://nextjs.org/docs/messages/invalid-next-config

And it still works locally, but not in Vercel.

I think you need to move localePath into the exported module root scope:

module.exports = {
  i18n: {
    locales: ['de-CH', 'fr', 'en'],
    defaultLocale: 'de-CH',
    localeDetection: true,
  },
  localePath: path.resolve('./public/locales'),
  reloadOnPrerender: process.env.NODE_ENV === 'development',
}

Not sure where it’s documented but it worked for me.

@samiulhsohan You need add the path of your locale files

// next-i18next.config.jjs
const path = require('path')

module.exports = {
  i18n: {
    defaultLocale: "en",
    locales: ["en", "fr"],
    localePath: path.resolve('./public/locales')
  },
};

I think this issue is back in recent versions (I’m on 13.2.2). I get a warning:

warn  - Invalid next.config.js options detected: 
warn  -     The value at .i18n has an unexpected property, localePath, which is not in the list of allowed properties (defaultLocale, domains, localeDetection, locales).
warn  - See more info here: https://nextjs.org/docs/messages/invalid-next-config

And it still works locally, but not in Vercel.

@isaachinman I am experiencing the same issue but for dynamic routes like pages/posts/[...slug.js]. Any idea how can I solve it? Can you please also add an example for dynamic routing on the example repo?