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

NextJS build fails with next-i18next when target is set to serverless #1311

Closed
phbernard opened this issue Jul 12, 2021 · 11 comments
Closed

Comments

@phbernard
Copy link

phbernard commented Jul 12, 2021

Describe the bug

When a NextJS app is built with npm run build while target is set to serverless in next.config.js, the build fails with:

Unhandled error during request: Error: Cannot find module '/path/to/project/next-i18next.config.js'

Occurs in next-i18next version

next-i18next Npm package version 8.5.3

Steps to reproduce

With a sample project

Positive case:

git clone https://github.com/phbernard/next-i18next-issue.git
npm install
npm run build # Works, as expected

Now, edit next.config.js and uncomment the line //target: 'serverless',. Then, build again:

npm run build # This time, the build fails

From scratch

To re-create the demo project above and check for yourself:

  • Create a NextJS app with yarn create next-app
  • Perform a basic next-i18next setup, following the project README:
    • Install next-i18next
    • Create some common.json (make them empty)
    • Create and populate next-i18next.config.js
    • Modify next.config.js
    • Modify pages/_app.js
    • Add getStaticProps to pages/index.js

Then proceed as above:

  • Run npm run build: it works
  • Set target: 'serverless' in next.config.js, run npm run build again: it fails

Expected behaviour

Build should succeed with target set to serverless. Or there should be a documented workaround.

Additional context

Note that serverless is a requirement for Netlify, which is a mainstream way to deploy Next. Therefore, this issue might be often encountered.

This issue has already been described in #911 . I opened a new one because I felt the title was clearer, plus it comes with a demo repos to reproduce it.

@phbernard phbernard changed the title NextJS build fails with next-i18next when target is set to 'serverless' NextJS build fails with next-i18next when target is set to serverless Jul 12, 2021
@isaachinman
Copy link
Contributor

Can you provide official documentation on target: 'serverless'? I'm not sure if this config option is still officially supported, as I can't find anything relevant on it.

@isaachinman
Copy link
Contributor

Please see: vercel/next.js#20487 (comment)

@phbernard
Copy link
Author

Thank you for your quick answer!

Here I'm focusing on deployment on Netlify, which is my target environment as you can guess.

Unfortunately, removing target: 'serverless' does not work. In Netlify build logs, it is stated that target is automatically set to this value:

────────────────────────────────────────────────────────────────
3:34:41 PM:   1. onPreBuild command from @netlify/plugin-nextjs             
3:34:41 PM: ────────────────────────────────────────────────────────────────
3:34:41 PM: ​
3:34:41 PM: Using Next.js 11.0.1
3:34:41 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
3:34:41 PM: The "target" config property must be one of "serverless", "experimental-serverless-trace". Building with "serverless" target.

So I tried with target: 'experimental-serverless-trace', the other accepted value. It works: there is no longer an issue with next-i18next.config.js and the application can be successfully deployed on Netlify.

I'm not very satisfied with this trial-and-error process, but clearly this has nothing to do with next-i18next anymore. Thanks again!

@madshargreave
Copy link

Encountering the same issue

@phbernard
Copy link
Author

@madshargreave Does experimental-serverless-trace help?

@tgmarinho
Copy link

I created this issue: netlify/next-runtime#595
same error here.

@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 ?

@miinnnn2
Copy link

miinnnn2 commented Nov 3, 2021

Anyone solve this problem?

@miinnnn2
Copy link

miinnnn2 commented Nov 3, 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 ?

Would you solve this problem?

@lucascampelo
Copy link

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 ?

Would you solve this problem?

Not yet. Currently I'm deploying on Vercel's servers stead of configure my own deploy with serverless framework.

@guiferreira-vx
Copy link

Has anyone found a solution to the problem?

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

7 participants