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

issue with localePath in monorepo when deployed to Vercel #1553

Closed
jakubHynek opened this issue Nov 29, 2021 · 2 comments
Closed

issue with localePath in monorepo when deployed to Vercel #1553

jakubHynek opened this issue Nov 29, 2021 · 2 comments

Comments

@jakubHynek
Copy link

jakubHynek commented Nov 29, 2021

Describe the bug

We have this project structure, where I need to deploy one app from monorepo to Vercel, I created simpified reprocudction in GitHub repo.
The problem is with next-i18next.config.js and localePath. When I use path.resolve('./public/locales'), then the serverless function on Vercel can't find the locale files, when I use path.resolve('./packages/parent/public/locales'), then the pre-rendering function can't find the locale files, so there is this problem in recognizing if the config is in getStaticProps or getServerSideProps and I cant get it to work. Right now the config looks like this:

/* next-i18next.config.js */
const path = require('path');

module.exports = {
    i18n: {
      defaultLocale: 'cs',
      locales: ['en', 'cs'],
      localePath: process.env.VERCEL ? path.resolve('./packages/parent/public/locales') : path.resolve('./public/locales')
    },
  };

I tried to play with process.browser and typeof window === 'undefined' but that did not help.

When path.resolve('./public/locales') it crashes when trying to load SSR rendered page with error:

info  - Loaded env from /var/task/.env
2021-11-29T13:47:12.977Z	0e7d42ba-aaae-4c84-bb41-96a5a3fb6847	ERROR	Error: ENOENT: no such file or directory, scandir '/var/task/public/locales/en'
    at Object.readdirSync (fs.js:1047:3)
    at getLocaleNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:175:23)
    at /var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:181:20
    at Array.map (<anonymous>)
    at getNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:180:44)
    at createConfig (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:221:29)
    at _callee$ (/var/task/node_modules/next-i18next/dist/commonjs/serverSideTranslations.js:199:53)
    at tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:294:22)
    at Generator.next (/var/task/node_modules/regenerator-runtime/runtime.js:119:21) {
  errno: -2,
  syscall: 'scandir',
  path: '/var/task/public/locales/en',
  page: '/'
}
RequestId: 0e7d42ba-aaae-4c84-bb41-96a5a3fb6847 Error: Runtime exited with error: exit status 1
Runtime.ExitError

When path.resolve('./package/parent/public/locales') it crashes during build with exit message:

Error occurred prerendering page "/en". Read more: https://nextjs.org/docs/messages/prerender-error
Error: ENOENT: no such file or directory, scandir '/vercel/path0/packages/parent/packages/parent/public/locales/en'
     at Object.readdirSync (fs.js:1047:3)
     at getLocaleNamespaces (/vercel/path0/node_modules/next-i18next/dist/commonjs/config/createConfig.js:175:23)
     at /vercel/path0/node_modules/next-i18next/dist/commonjs/config/createConfig.js:181:20
     at Array.map (<anonymous>)
     at getNamespaces (/vercel/path0/node_modules/next-i18next/dist/commonjs/config/createConfig.js:180:44)
     at createConfig (/vercel/path0/node_modules/next-i18next/dist/commonjs/config/createConfig.js:221:29)
     at _callee$ (/vercel/path0/node_modules/next-i18next/dist/commonjs/serverSideTranslations.js:199:53)
     at tryCatch (/vercel/path0/node_modules/regenerator-runtime/runtime.js:63:40)
     at Generator.invoke [as _invoke] (/vercel/path0/node_modules/regenerator-runtime/runtime.js:294:22)
     at Generator.next (/vercel/path0/node_modules/regenerator-runtime/runtime.js:119:21)}
RequestId: 1d6d712f-02d3-4029-8277-7bf418949555 Error: Runtime exited with error: exit status 1
Runtime.ExitError

Occurs in next-i18next version

^9.2.0

Steps to reproduce

Reproduction repository:

https://github.com/jakubHynek/lerna-monorepo

There is packages/parent which is basic next app created with yarn create next-app --typescript

packages/child not important for this issue - exports one basic function

Steps

yarn install
npx vercel
  • follow the steps of Vercel initialization

  • setup vercel project on their site:
    FRAMEWORK PRESET: Next.js
    BUILD COMMAND: yarn workspace parent run build
    OUTPUT DIRECTORY: packages/parent/.next
    leave Root Directory setting empty

  • either crash at build or at server side rendered page

@isaachinman
Copy link
Contributor

isaachinman commented Nov 29, 2021

@jakubHynek This package's repo itself is a monorepo, and the simple example is deployed on Vercel. You may need to change this setting:

Screen Shot 2021-11-29 at 14 32 09

@jakubHynek
Copy link
Author

So much pain for this mistake. Thank you very much!

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

2 participants