serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

Problem with deploying ssg and ssr pages using serverless and next-i18next - DELETED

Open TinaTahvildari opened this issue 5 years ago • 5 comments

TinaTahvildari avatar Nov 29 '21 13:11 TinaTahvildari

I have the same problem. Any news about it?

ciceropablo avatar Nov 29 '21 17:11 ciceropablo

Well I think my problem also relates to this. Althought Iam using SST, Serverless Stack, to deploy it uses pretty much same cdk construct from this repository. Lambda crashes with:

ERROR Error: Cannot find module '/var/task/next-i18next.config.js' at webpackEmptyContext (/var/task/chunks/474.js:9:10) at /var/task/chunks/638.js:248:72 { code: 'MODULE_NOT_FOUND'} | 2021-12-06T20:13:37.133Z bbbe90c8-e91c-4d20-b9bf-52c098b26d73 ERROR Error: Cannot find module '/var/task/next-i18next.config.js' at webpackEmptyContext (/var/task/chunks/474.js:9:10) at /var/task/chunks/638.js:248:72 { code: 'MODULE_NOT_FOUND' }

Mikko-AM avatar Dec 06 '21 20:12 Mikko-AM

Got it working. I simply needed to include next-i18next.config.js and give it as parameter to serverSideTranslation. Better explanation at the link:

https://githubmemory.com/repo/aws-amplify/amplify-console/issues/2111?page=1

Mikko-AM avatar Dec 06 '21 21:12 Mikko-AM

I had the same issue but I've just resolved it based on @Mikko-AM 's answer.

my old code was like this

// pages/_app.tsx
(...)
export default appWithTranslation(MyApp);

// pages/index.tsx
(...)
export async function getStaticProps({ locale }) {
  return { props: { ...(await serverSideTranslations( locale, ['common']) } };
}

And I fixed like this.

// pages/_app.tsx
import i18nConfig from '../next-i18next.config';
(...)
export default appWithTranslation(MyApp, i18nConfig);

// pages/index.tsx
import i18nConfig from '../next-i18next.config';
(...)
export async function getStaticProps({ locale }) {
  return { props: { ...(await serverSideTranslations( locale, ['common'], i18nConfig) } };
}

kyun avatar Dec 19 '21 15:12 kyun

Weird problem but the solutions by @Mikko-AM and @kyun worked pretty well in my case.

Peroconino avatar Nov 07 '22 21:11 Peroconino