Thanks to visit codestin.com
Credit goes to github.com

Skip to content

createTranslation() function does not work on App dir (NextJS 15) if I don't retrieve params.lang first. #1240

@jbprod-tech

Description

@jbprod-tech

What version of this package are you using? [email protected], with [email protected]

What operating system, Node.js, and npm version? Windows, Node 22.14.0, and npm 10.8.2

What happened?
In one of my page (/app/[lang]/page.js), I have to retrieve the t function to translate messages.
I'm using this code: const { t } = createTranslation();
But it doesn't work, unless I retrieve the language first.

So, I have to do:

export default async function HomePage({ params }) {
  const { lang } = await params;
	const { t } = createTranslation();

Instead of simply doing:

export default async function HomePage() {
	const { t } = createTranslation();

The error message displayed is:

 ⨯ Error [TypeError]: Cannot read properties of undefined (reading 'localesToIgnore')
    at Module.generateMetadata (webpack-internal:///(rsc)/./app/%5Blang%5D/page.js:44:96)
    at JSON.parse (<anonymous>) {
  environmentName: 'Server',
  digest: '2727303738'
}

What did you expect to happen? It should work without having to retrieve the language first.

Are you willing to submit a pull request to fix this bug? No.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions