next-translate: ENOENT: no such file or directory, scandir '....\monorepo\pages'

Hi my nextjs root is inside a monorepo as ./apps/web/ but I get this error on start:

ENOENT: no such file or directory, scandir 'monorepo\pages'

Is it possible to scan until you hit the first i18n.json or something along those lines, then you know the root where ./pages directory is to be expected

Thanks! Great project

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 50 (17 by maintainers)

Most upvoted comments

@mvierssen You can copy pages from .next folder as a temporary workaround, to not to copy source

I am using 1.0.1 version, it works fine with copied pages 1.0.7 is failing

Hi @gsambrotta, @krystianjj

As of 1.0.3, usage with NX brings this error:

err

You will not be able to use it, unfortunately 😦

Once PR #527 got merged, next-translate will become NX-compatible.

To setup next-translate with NX, you have to:

(a) Either pass env variable NEXT_TRANSLATE_PATH every time you run nx commands:

 npx cross-env NEXT_TRANSLATE_PATH=apps/myAppName nx serve myAppName

(b) or create .local.env file in the workspace root folder and define the var there:

// .local.env

NEXT_TRANSLATE_PATH=apps/myAppName

With (b) all nx commands will automatically read env from .local.env. Running nx serve myAppName will just work.

Hi @sergeyshaykhullin, You have different problem… Nextjs must have pages directory because nextjs have build in router. Check if you copy pages to correct main directory of project.

@aralroca yeah, of course. Thanks.

From 1.0.5-canary.1 all goes smooth, no issues so far.

Hi @shelooks16, @aralroca I just tested next-translate@1.04-canary.2 with NX and I confirm, now everything working great 😃 Thank you 👍

Did anyone manage to deploy to production using NX-monorepo or any monorepo? My guess is that .env.local is somehow not taken into account or not pointing to the same path when building for prod with npm run start. Everything works just fine in dev (when using npx nx run myapp:serve). But on prod, I use npm run start (> nx start) it fails.

@aralroca @shelooks16 Thank you, I have fixed the above error. Thanks a lot

Hi @karolbilicki

1.01 - the workaround with copied pages works, but I get the error related to $RefreshHelpers$’ string when I run nx start myapp (dev envrionment without building)

this is fixed in 1.0.4 and 1.0.5. Below these versions you won’t be able to pair NX and next-translate 😦

1.05 - the workaround with copied pages doesn’t work (prod), dev environment works fine

are you using docker? I have been using the workaround with docker up until now and haven’t experienced any problems.

Hi, we’re also getting the same error. I believe there’s a bug in the templateWithHoc method because the code parsed into the method is valid but the output is not.

Input:

    // Legacy CSS implementations will `eval` browser code in a Node.js context
    // to extract CSS. For backwards compatibility, we need to check we're in a
    // browser context before continuing.
    if (typeof self !== 'undefined' &&
        // AMP / No-JS mode does not inject these helpers:
        '$RefreshHelpers$' in self) {

Output:

    // Legacy CSS implementations will `eval` browser code in a Node.js context
    // to extract CSS. For backwards compatibility, we need to check we're in a
    // browser context before continuing.
    if (typeof self !== 'undefined' &&
        // AMP / No-JS mode does not inject these helpers:
        '$RefreshHelpers
// @ts-ignore
    export default __appWithI18n(__Page_Next_Translate__, {

Hope it helps. 🙏

Here’s how to replicate:

npx create-nx-workspace@next

choose Next.js & CSS

npm i next-translate

next.config.js:

const withNx = require('@nrwl/next/plugins/with-nx');
const nextTranslate = require('next-translate')

module.exports = withNx({
  ...nextTranslate({
    locales: ["en", "fr"],
  }),
});

/i18n.json:

{
  "locales": ["en", "fr"],
  "defaultLocale": "en",
  "pages": {
    "*": ["common"],
    "/": ["home"]
  }
}

result:

ENOENT: no such file or directory, scandir 'C:\p\_temp\testt\pages'