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

NX mono-repo cannot find module i18n #1103

Closed
andersbss opened this issue Jul 7, 2023 · 9 comments
Closed

NX mono-repo cannot find module i18n #1103

andersbss opened this issue Jul 7, 2023 · 9 comments

Comments

@andersbss
Copy link

andersbss commented Jul 7, 2023

What version of this package are you using?
"next-translate": "^2.4.4",

Related packages:
"next-translate-plugin": "^2.4.4",
"i18next": "^23.2.8",
"next": "13.4.9",
"nx": "16.2.2",
"@nx/next": "16.4.2",

What operating system, Node.js, and npm version?
OS: macOS Monterey 12.5.1
Node: v20.2.0 (also tested with node 16)
Yarn: 1.22.19

What happened?
Trying to provide path to the i18n.json file in a mono-repo application using NX.

.env:
NEXT_TRANSLATE_PATH=./apps/basic

next.config.json:
`
/* eslint-disable @typescript-eslint/no-var-requires */
const withNx = require('@nx/next/plugins/with-nx');
const nextTranslate = require('next-translate-plugin');
const withImages = require('next-images');

/**

  • @type {import('@nx/next/plugins/with-nx').WithNxOptions}
    **/
    const nextConfig = {
    images: {
    domains: [
    ...
    ],
    },
    nx: {
    // Set this to true if you would like to to use SVGR
    // See: https://github.com/gregberge/svgr
    svgr: false,
    },
    publicRuntimeConfig: {
    env: {
    ...
    },
    },
    modularizeImports: {
    '@mui/material': {
    transform: '@mui/material/{{member}}',
    },
    '@mui/icons-material': {
    transform: '@mui/icons-material/{{member}}',
    },
    },
    };

module.exports = withNx(withImages(nextTranslate(nextConfig)));
`
Error when running "yarn nx run basic:build":

Build error occurred
Error: Cannot find module '/Users/andersbs/Documents/GitHub/xpand-frontend/apps/basic/apps/basic/apps/basic/i18n'
Require stack:

  • /Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/next-translate-plugin/lib/cjs/index.js
  • /Users/andersbs/Documents/GitHub/xpand-frontend/apps/basic/next.config.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1070:15)
    at /Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/next/dist/server/require-hook.js:185:36
    at Module._load (node:internal/modules/cjs/loader:923:27)
    at Module.require (node:internal/modules/cjs/loader:1137:19)
    at require (node:internal/modules/helpers:121:18)
    at nextTranslate (/Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/next-translate-plugin/lib/cjs/index.js:26:14)
    at Object. (/Users/andersbs/Documents/GitHub/xpand-frontend/apps/basic/next.config.js:68:36)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/next-translate-plugin/lib/cjs/index.js',
    '/Users/andersbs/Documents/GitHub/xpand-frontend/apps/basic/next.config.js'
    ]
    }
    Error occurred while trying to run the npx next build
    Error: Command failed: npx next build
    at checkExecSyncError (node:child_process:885:11)
    at execSync (node:child_process:957:15)
    at /Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/@nx/next/src/executors/build/build.impl.js:49:42
    at Generator.next ()
    at /Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/tslib/tslib.js:169:75
    at new Promise ()
    at Object.__awaiter (/Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/tslib/tslib.js:165:16)
    at buildExecutor (/Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/@nx/next/src/executors/build/build.impl.js:20:20)
    at /Users/andersbs/Documents/GitHub/xpand-frontend/node_modules/nx/src/command-line/run/run.js:101:23

What did you expect to happen?
According to the docs "NEXT_TRANSLATE_PATH=./apps/basic" should do the trick. This has also worked in earlier versions.

Expected path:
/Users/andersbs/Documents/GitHub/xpand-frontend/apps/basic/i18n

Actual path which causes the error:
/Users/andersbs/Documents/GitHub/xpand-frontend/apps/basic/apps/basic/apps/basic/i18n

Are you willing to submit a pull request to fix this bug?
Yes

@aralroca
Copy link
Owner

aralroca commented Jul 7, 2023

Probably is related with this PR: aralroca/next-translate-plugin#55

@Thevyn
Copy link

Thevyn commented Jul 7, 2023

Same problem, had to change NEXT_TRANSLATE_PATH to ../../

@andersbss
Copy link
Author

Same problem, had to change NEXT_TRANSLATE_PATH to ../../

This works when running build, but when Im trying to start the production build it fails because of the path.

@laneme
Copy link

laneme commented Jul 14, 2023

This works when running build, but when Im trying to start the production build it fails because of the path.

Try NEXT_TRANSLATE_PATH=./ yarn nx serve app --prod when serving. Replace ./ with somth else maybe if doesnt work.

@mlnima
Copy link

mlnima commented Jul 15, 2023

almost the same here: Module not found: Can't resolve ' next-translate/withTranslationClientComponent '
I just went from 2.3.0-canary.3 to 2.4.4 using turbo repo

@aralroca
Copy link
Owner

@mlnima ensure that the next-translate-plugin is in the same version than next-translate. This internal property is removed and the new version of the plugin uses another one.

You should have been warned when installing the dependencies as we are restricting with peerDependencies 🤔

@mlnima
Copy link

mlnima commented Jul 15, 2023

Thank You, it was my bad 🙂

@mlnima
Copy link

mlnima commented Aug 2, 2023

This is an update about what I did for other people who are facing the same issue using next-translate,
my goal was to server the default language on the path "/" and the rest on "/:locale", however, I tried so hard to fix the issue but it was very simply by not using next-translate or any other lib. I just changed my translation data structure according to the nextJs docs, I had an issue trying to rewrite or redirect the user in middleware.ts or .js but now it's working fine. for longer as you are using server components it would not put a noticeable weight on your app. but I've lost a few good abilities.

@aralroca
Copy link
Owner

aralroca commented Aug 4, 2023

Duplicated of #1121 (comment)

@aralroca aralroca closed this as completed Aug 4, 2023
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

5 participants