aralroca / next-translate

Next.js plugin + i18n API for Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
2.59k stars 208 forks source link

NX mono-repo cannot find module i18n #1103

Closed andersbss closed 11 months ago

andersbss commented 1 year ago

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');

/**

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

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 commented 1 year ago

Probably is related with this PR: https://github.com/aralroca/next-translate-plugin/pull/55

Thevyn commented 1 year ago

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

andersbss commented 12 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

Thank You, it was my bad 🙂

mlnima commented 11 months ago

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 commented 11 months ago

Duplicated of https://github.com/aralroca/next-translate/issues/1121#issuecomment-1665699301