Next-i18next: Unable To Successfully Deploy Example To Now

Created on 27 Nov 2019  路  12Comments  路  Source: isaachinman/next-i18next

Describe the bug

I attempted to deploy the example code to now using the existing setup. There were some clear issues that I was able to resolve, but after solving those issues the release was still unsuccessful. The error I received in the now logs after the release is below.

ENOENT: no such file or directory, scandir '/var/task/static/locales/en'

Occurs in next-i18next version

v2.1.1

Steps to reproduce

  • Clone next-i18next repository
  • Navigate to examples/simple directory
  • Remove next-i18next, react, react-dom from package.json
  • Run npm install
  • Run npm install next-i18next react react-dom
  • Run now

Expected behaviour

Example solution to deploy to now site.

OS (please complete the following information)

  • Device: MBP 2019 15"
  • Browser: N/A

Additional context

After some research I found out that NextJS version 9 prefers the use of build-time configuration over runtime configuration, https://github.com/zeit/next.js/#runtime-configuration.

Warning: Generally you want to use build-time configuration to provide your configuration. The reason for this is that runtime configuration adds rendering / initialization overhead and is incompatible with automatic static optimization.

I have been reading some other issues and pull requests and following some movement of files to public folder. I also have been following your discussions about offering the middleware with NextJS serverless. Some of those may solve this issue as well. If it would be possible to have a working example, perhaps after the pull request moving to use the public folder that would be amazing.

Most helpful comment

@deantheiceman I am hoping to start a Now deployment pull request toward the end of the week. It might come up during that work.

All 12 comments

Hi @someyoungideas. Thanks for a thorough report, and thanks for having a look around.

It sounds like the blocking point you've hit is that next-i18next reaches into the filesystem, which sounds unrelated to use of the public dir or middleware at all. It's in fact a long-standing issue that no one has opened a PR for as of yet.

If you'd like to get involved, I would be happy to point you in the right direction.

578

Any tips on how to solve this temporarily? I'm building a dead simple version which just needs a common lib file.

Is it because now can't access the filesystem?

@deantheiceman I am hoping to start a Now deployment pull request toward the end of the week. It might come up during that work.

After some research I found out that NextJS version 9 prefers the use of build-time configuration over runtime configuration, https://github.com/zeit/next.js/#runtime-configuration.

Until #274 is resolved that's kind of a moot point. The custom server means you opt out of it anyway.

Most likely this will (only) be resolved when next-i18next is rewritten via the upcoming official NextJs plugin system.

@someyoungideas Can you help resolve this issue? Is this either:

  1. A duplicate of #274
  2. A request to remove filesystem-specifics

Please let me know.

I would agree that this is more likely a duplicate of #274. I apologize for not keeping closer tabs on it.

Sorry! please I dont understand what is the solution for this error. Also I have this error when my nextjs app is deployed on AWS CloudFront.
Error: ENOENT: no such file or directory, scandir '/var/task/public/static/locales/es'

I'm having the same problem deploying with serverless-nextjs component and can't find a fix for it.

I'm having the same problem deploying with serverless-nextjs component and can't find a fix for it.

@morjanmihail Please! Serverless-next Team developers, Daniel Phang made a new release @sls-next/serverless-component 1.19.0 alpha to solve this error and gives us an excellent solution, please review this link (the new release allow to add in serverless.yml a new input for build:

https://github.com/serverless-nextjs/serverless-next.js/issues/767#issuecomment-727264852

Like this:
serverless.yml

myNextApp:
  component: "@sls-next/[email protected]"

  inputs:
    build:
      postBuildCommands: ["node post-build.js"]

and a js file (in root e.g.):

// post-build.js
const fs = require('fs-extra')

console.log('-> Copying locales directory...');
const localeSrc = './public/locales';
const localeDest = './.serverless_nextjs/default-lambda/public/locales';
fs.copySync(localeSrc, localeDest, { recursive: true });
console.log('Locale directory was copied successfully');

I tried it few times and it didn't work. After deleting .next / .serverless / .serverless_nextjs it worked out! Many thanks!

Kind regards,
Mihai

Was this page helpful?
0 / 5 - 0 ratings