-
-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(server-side): custom default config path #2084
Conversation
cool... |
included in v13.1.0 |
This change broke production on Vercel but I don't know why:
|
just tested if our simple example deploys on Vercel... and seems to work without any issues: https://github.com/i18next/next-i18next/tree/master/examples/simple |
Thanks, @adrai. I did more testing. It seems like it only affects dynamic routes. You can re-produce the issue with this repo: https://github.com/quanglam2807/next-i18next-simple-test/blob/main/pages/pages/%5Bpage%5D.tsx |
@intpp can you have a look at it? |
@quanglam2807 this is really strange... to me this looks like to be a Vercel issue... do you want to try to open an issue/discussion here? https://github.com/vercel/community/discussions |
@quanglam2807 It seems like, as soon as the serverSideTranlsations file accesses process.env the error occurs: c6ccf41#diff-78da8fd247ac10bc4179e3dad343177bb6bf49923dcc4bd6cab86babfae025bfL27 @intpp it would be nice if you could investigate why this happens with the Vercel team/support |
Thank you, @adrai. I also suspected the same thing but oddly enough, calling |
I'll check |
@adrai Hi. I did some research on the problem. It causes by the library https://github.com/vercel/nft, which is used by the Next.js' https://nextjs.org/docs/advanced-features/output-file-tracing
When we use It works if we set let DEFAULT_CONFIG_PATH = './next-i18next.config.js'
// Added
if (process.env.I18NEXT_DEFAULT_CONFIG_PATH) {
DEFAULT_CONFIG_PATH = process.env.I18NEXT_DEFAULT_CONFIG_PATH
}
export const serverSideTranslations = async (
initialLocale: string,
namespacesRequired: string[] | undefined = undefined,
configOverride: UserConfig | null = null,
extraLocales: string[] | false = false
): Promise<SSRConfig> => {
if (typeof initialLocale !== 'string') {
throw new Error(
'Initial locale argument was not passed into serverSideTranslations'
)
}
let userConfig = configOverride
const configPath = path.resolve(DEFAULT_CONFIG_PATH)
if (
!userConfig &&
fs.existsSync(configPath)
) {
userConfig = await import(configPath)
}
if (userConfig === null) {
throw new Error(`next-i18next was unable to find a user config at ${configPath}`)
} It works for a single application and a monorepo if I have published the test version https://www.npmjs.com/package/intpp-next-i18next?activeTab=explore with the change and tested it on Vercel - It works (https://github.com/intpp/i18next-demo). I'll create a new PR with the change. |
To solve issues like this one: nrwl/nx#4983, and to not create hacky functions I suggest the following change.
It doesn't break anything but it adds the ability to set the default config path.
It will allow you to simply use the package in NX monorepo with the changes from the
dynamic path
example.