question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Hey, I’m using serverless and next-i18next with s3bucket and cloadfront. I am almost new to this topic and would be very grateful if anyone could guide me.

Describe the bug


There is no problem running project locally in develop mode or in production mode but in deployment when i tried to load translates in getStaticProps i got this error:
Error: Command failed with exit code 1: node_modules/.bin/next build
warn  - No ESLint configuration detected. Run next lint to begin setup
(node:15268) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
warn  - Compiled with warnings

./node_modules/next-i18next/dist/commonjs/serverSideTranslations.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/i18next-fs-backend/cjs/readFile.js
Critical dependency: the request of a dependency is an expression

./node_modules/i18next-fs-backend/cjs/readFile.js
Critical dependency: the request of a dependency is an expression

Unhandled error during request: Error: Cannot find module 'F:\Next js\Edsurfing\edsurfing\next-i18next.config.js'
    at webpackEmptyContext (F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\108.js:9:10)
    at F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\709.js:300:72 {
  code: 'MODULE_NOT_FOUND'
}

Error occurred prerendering page "/en/auth/signup". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Cannot find module 'F:\Next js\Edsurfing\edsurfing\next-i18next.config.js'
    at webpackEmptyContext (F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\108.js:9:10)
    at F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\709.js:300:72
Unhandled error during request: Error: Cannot find module 'F:\Next js\Edsurfing\edsurfing\next-i18next.config.js'
    at webpackEmptyContext (F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\108.js:9:10)
    at F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\709.js:300:72 {
  code: 'MODULE_NOT_FOUND'
}

Error occurred prerendering page "/sv/auth/signup". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Cannot find module 'F:\Next js\Edsurfing\edsurfing\next-i18next.config.js'
    at webpackEmptyContext (F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\108.js:9:10)
    at F:\Next js\Edsurfing\edsurfing\.next\serverless\chunks\709.js:300:72

> Build error occurred
Error: Export encountered errors on following paths:
        /en/auth/signup
        /sv/auth/signup
    at F:\Next js\Edsurfing\edsurfing\node_modules\next\dist\export\index.js:487:19
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Span.traceAsyncFn (F:\Next js\Edsurfing\edsurfing\node_modules\next\dist\telemetry\trace\trace.js:60:20)
    at async F:\Next js\Edsurfing\edsurfing\node_modules\next\dist\build\index.js:833:17
    at async Span.traceAsyncFn (F:\Next js\Edsurfing\edsurfing\node_modules\next\dist\telemetry\trace\trace.js:60:20)
    at async F:\Next js\Edsurfing\edsurfing\node_modules\next\dist\build\index.js:707:13
    at async Span.traceAsyncFn (F:\Next js\Edsurfing\edsurfing\node_modules\next\dist\telemetry\trace\trace.js:60:20)
    at async Object.build [as default] (F:\Next js\Edsurfing\edsurfing\node_modules\next\dist\build\index.js:77:25)
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types...
info  - Creating an optimized production build...
info  - Collecting page data...
info  - Generating static pages (0/14)
meeting response:  null
atendee Response:  null
undefined
info  - Generating static pages (3/14)
meeting response:  null
atendee Response:  null
undefined
meeting response:  null
atendee Response:  null
undefined
info  - Generating static pages (6/14)
info  - Generating static pages (10/14)
info  - Generating static pages (14/14)

and this is where i use getStaticProps: Screenshot (6)

Then I changed this page to ssr and i got no error in deploying but after finishing the diployment, I received “404 error - This page could not be found” on all the pages where I used next-i18next and in all three subpaths:

/auth/signup
/en/auth/signup
/sv/auth/signup

Screenshot (9)

Here is next.config.js and next-i18next.config.js files:

Screenshot (11) Screenshot (12)

serverless.yml:

Screenshot (13)

post-build.js: Screenshot (14)

I have been looking for a solution to this problem for days.Is this something that the Serverless doesn’t support yet, or am I doing something wrong? Thanks!


next-i18next and next version:

next-i18next: 9.2.0 next: 11.1.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
kyuncommented, Dec 19, 2021

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) } };
}
2reactions
Mikko-AMcommented, Dec 7, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serverless Next.js Component - Serverless Framework: Plugins
If you are encountering code size issues, please try the following: Optimize your code size: reduce # dependencies in your SSR pages and...
Read more >
Next.js TypeScript serverless deploy with SSR and ISR with ...
We'll deploy a Next.js webapp in AWS using Lambda@Edge and CloudFront ... Server Side Rendering is great to solve some of these problems...
Read more >
next-i18next - npm
Start using next-i18next in your project by running `npm i ... and configuration options into pages as props with SSG/SSR support.
Read more >
All side optimized Next.js translations - DEV Community ‍ ‍
To work with static-site generation (SSG) we need to use the next export command, but... Error: i18n support is not compatible with next...
Read more >
SSR (additional components) - react-i18next documentation
next-i18next @v5.0.0 supports Next.js v9.5 in Serverless mode (as of July 2020). ... a simple tutorial on how to best use next-i18next in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found