Skip to content
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

next build 8.0.0-beta #911

Closed
mateusvahl opened this issue Jan 14, 2021 · 14 comments
Closed

next build 8.0.0-beta #911

mateusvahl opened this issue Jan 14, 2021 · 14 comments

Comments

@mateusvahl
Copy link

Describe the bug

Hi, first thank very much for the update, I recently updated a repo to use the beta version and everything seems to work fine during developing mode, however, I noticed the follow issue when building nextjs in production mode:

Cannot find module '/web/next-i18next.config.js'

  1. Run: $ NODE_ENV=production next build

  2. Nextjs outptus:

Loaded env from /web/.env
info  - Creating an optimized production build
warn  - Compiled with warnings

info  - Collecting page data
[=   ] info  - Generating static pages (0/5)Unhandled error during request: Error: Cannot find module '/web/next-i18next.config.js'
    at webpackEmptyContext (/web/.next/serverless/pages/auth/login.js:38010:10)
    at /web/.next/serverless/pages/auth/login.js:343:90 {
  code: 'MODULE_NOT_FOUND'
}

Error occurred prerendering page "/ae/auth/login". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module '/web/next-i18next.config.js'
    at webpackEmptyContext (/web/.next/serverless/pages/auth/login.js:38010:10)
    at /web/.next/serverless/pages/auth/login.js:343:90
[    ] info  - Generating static pages (1/5)Unhandled error during request: Error: Cannot find module '/web/next-i18next.config.js'
    at webpackEmptyContext (/web/.next/serverless/pages/auth/login.js:38010:10)
    at /web/.next/serverless/pages/auth/login.js:343:90 {
  code: 'MODULE_NOT_FOUND'
}

Error occurred prerendering page "/en/auth/login". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module '/web/next-i18next.config.js'
    at webpackEmptyContext (/web/.next/serverless/pages/auth/login.js:38010:10)
    at /web/.next/serverless/pages/auth/login.js:343:90
react-i18next:: You will need to pass in an i18next instance by using initReactI18next
[=   ] info  - Generating static pages (2/5)react-i18next:: You will need to pass in an i18next instance by using initReactI18next
react-i18next:: You will need to pass in an i18next instance by using initReactI18next
info  - Generating static pages (5/5)

Files

./web/next-i18next.config.js

const path = require("path");

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

./web/next.config.js

module.exports = {
  ...
  i18n: {
    defaultLocale: "en",
    locales: ["en", "ae"],
  },
};

./web/src/pages/auth/login.tsx

import { NextPage } from "next";
import Head from "next/head";
import { withTranslation, WithTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";

interface Props extends WithTranslation {}

const _Page: NextPage<Props> = (props: Props) => {
  const { t } = props;

  // ... 
  
  return <div />
};

export const getStaticProps = async ({ locale }) => ({
  props: {
    ...(await serverSideTranslations(locale, ["auth-login", "common"])),
  },
});

export default withTranslation("auth-login")(_Page);

Occurs in next-i18next version

"next": "10.0.5",
"next-i18next": "8.0.0-beta.0"

OS (please complete the following information)

  • Docker / linux
@mateusvahl
Copy link
Author

Update: Issue seems to be caused by setting target: "serverless" on next.config.js:

module.exports = {
  target: "serverless",
  i18n: {
    defaultLocale: "en",
    locales: ["en", "ae"],
  },
};

Not sure if it's related to this package at this point.

@isaachinman
Copy link
Contributor

@mateusvahl Not sure what exactly that config option does, but you'll need to make sure that your next-i18next.config.js config file is available on the fs. I don't think this is a next-i18next bug. Let me know if you have any further questions. Good luck!

@michele-amati
Copy link

Update: Issue seems to be caused by setting target: "serverless" on next.config.js:

module.exports = {
  target: "serverless",
  i18n: {
    defaultLocale: "en",
    locales: ["en", "ae"],
  },
};

Not sure if it's related to this package at this point.

Hi, I'm having the same problem, would you mind sharing your final solution? Did you go with removing "serverless"? Looking for possible consequences I've found another post of yours https://github.com/vercel/next.js/discussions/21174 and the part:

Serverless deployment dramatically improves reliability and scalability by splitting your application into smaller parts

scared me a little

@mvilkki
Copy link

mvilkki commented Mar 16, 2021

@michele-amati Had same issue. Project did run on dev mode but not in build mode. Issue arose cause localePath: in next-i18next.config.js was pointing to incorrect place. In my case correct config was localePath: path.resolve('./public/locales'),.

Main problem is quite bad error trace by default with next so this mistake in config was hard to notice.

Try to add experimental-serverless-trace as target to nex.config.js for debugging purposes to find your issue.

@rhoiyds
Copy link

rhoiyds commented Apr 19, 2021

Currently experiencing this issue as well.

I've tried experimental-serverless-trace which didn't help, as well as configuring localePath.

Running the development server locally works fine and as expected, however a deployment using serverless always results in this error.

Any other solutions?

@mateusvahl
Copy link
Author

@rhoiyds do you have target: "serverless" on your next.config.js file? In my case I just removed that and it worked.

@rhoiyds
Copy link

rhoiyds commented Apr 20, 2021

@mateusvahl Thanks for replying. I've given removing target: "serverless" a try, but the same error occurs.
Unhandled error during request: { Error: Cannot find module '/builds/<PROJECT>/next-i18next.config.js'

Would you mind sharing your basic package.json and serverless.yml configs so I can try rule out package versioning issues? Or do you have any other suggestions for the being?

@phbernard
Copy link

I also get this issue. target set to serverless is clearly the culprit. I reproduced the issue in a fresh project and opened a new issue so maintainers can easily reproduce it: #1311 .

@phbernard
Copy link

@rhoiyds FYI experimental-serverless-trace did work for me, see #1311

You can play with this demo repo: https://github.com/phbernard/next-i18next-issue.git (just a fresh NextJS app and basic next-i18next setup). Change target to serverless/experimental-serverless-trace/(not set) in next.config.js to observe the differences: build only fails with serverless.

@lucascampelo
Copy link

lucascampelo commented Oct 19, 2021

I'm having the same issue using serverless framework with next + next-i18next. Seems like change the target to experimental-serverless-trace doesn't fix on deploy using serverless framework. Can anyone help me to understand the root cause ?

@tiagobbraga
Copy link

The same problem.

I'm having the same issue using serverless framework with next + next-i18next. Seems like change the target to experimental-serverless-trace doesn't fix on deploy using serverless framework. Can anyone help me to understand the root cause ?

@samwisekind
Copy link

samwisekind commented Jan 17, 2022

Having the same issue:

2022-01-17T15:04:33.254Z   ERROR   Unhandled error during request: Error: Cannot find module '/var/task/next-i18next.config.js'
    at webpackEmptyContext (/var/task/chunks/9122.js:9:10)
    at /var/task/chunks/6370.js:244:72
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  code: 'MODULE_NOT_FOUND'
}

Deployed via serverless-next.js to AWS with all three target values (serverless, experimental-serverless-trace, and omitted). The config file is present in the Lambda function.

@guiferreira-vx
Copy link

Has anyone found a solution to the problem?

@ekofi
Copy link

ekofi commented Oct 4, 2022

Any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests