next-translate icon indicating copy to clipboard operation
next-translate copied to clipboard

Can not find module i18n

Open chanphiromsok opened this issue 1 year ago • 12 comments

What version of this package are you using? "next-translate-plugin": "^2.5.2"

What operating system, Node.js, and npm version? node 16 yarn 1.22.19

What happened? Screen Shot 2023-07-24 at 10 40 24 AM

Are you willing to submit a pull request to fix this bug? I am so sorry I new to new ,I could not fix it

chanphiromsok avatar Jul 24 '23 03:07 chanphiromsok

Did you add i18n config file following this guide?

loukhin avatar Jul 24 '23 13:07 loukhin

@chanphiromsok would be great to know more details about your project. Maybe is something missing like i18n.js file. Thanks

aralroca avatar Jul 24 '23 15:07 aralroca

I follow the guide for nextjs 13 app directory also have config file i18n.js and locales folder in the root directory

chanphiromsok avatar Jul 25 '23 01:07 chanphiromsok

@chanphiromsok do you have a monorepo? https://github.com/aralroca/next-translate#13-how-to-use-next-translate-in-a-mono-repo

to better understand the problem if you share a repo reproducing the error we will see what happens. Thanks!

aralroca avatar Jul 25 '23 10:07 aralroca

I'm seeing the same issue. We're passing in a NEXT_TRANSLATE_PATH.

It seems to be something to do with this code in the plugin:

var basePath = pkgDir();
basePath = path_1.default.resolve(path_1.default.relative(basePath, process.env.NEXT_TRANSLATE_PATH || '.'));

My project structure is something like this:

Users/me
└── Development
    └── my-monorepo
        └── apps
            └── my-app
                ├── i18n.js
                ├── next.config.js
                └── other-files

My basePath is /Users/me/Development/my-monorepo. Inside my-monorepo, I have an app at apps/my-app, which is where my NextJS and Next Translate configs live. apps/my-app is what I set NEXT_TRANSLATE_PATH to.

The resulting basePath of the code above is /Users/me/Development/my-monorepo/apps/my-app/apps/my-app/apps/my-app.

This is when running through nx. For example, nx run my-app:serve:development.

I'm wondering if there is something going on with what is used to derive basePath here (i.e., pkgdir) versus what path might be using under the hood for path comparison (my guess is process.cwd()).

Edit to add: this is something I've started seeing after upgrading to Nx 16.

ian-hutchinson avatar Jul 25 '23 23:07 ian-hutchinson

I have the same error in my project with nx

image

ilchenkoArtem avatar Aug 04 '23 14:08 ilchenkoArtem

@chanphiromsok do you have a monorepo? https://github.com/aralroca/next-translate#13-how-to-use-next-translate-in-a-mono-repo

to better understand the problem if you share a repo reproducing the error we will see what happens. Thanks!

Hi sorry for late response Now I have skip this feature 😅

chanphiromsok avatar Aug 05 '23 01:08 chanphiromsok

@ilchenkoArtem how did you solve TS errors when running NX composePlugins?

mkbctrl avatar Aug 06 '23 15:08 mkbctrl

Just want to add a little more data that I found that might be related to this, at least in my case.

As I mentioned, I'm seeing this when using nx and upgrading to v16. While it's not listed in the breaking changes, one thing I noticed about v16 is that they now spin up webservers in the outputPath of your build target. Previously this wasn't the case, as it used the root instead.

Since the NextJS config gets read in both the build and serve phases, and those phases now run from different directories, this also causes issues with relative paths for the translate configs.

One workaround in this particular case is to inspect the phase (such as PHASE_PRODUCTION_SERVER or PHASE_PRODUCTION_BUILD) in the Next config and assign the correct path accordingly. Still no idea why the dev server path is so screwy, though (my above comment).

ian-hutchinson avatar Aug 11 '23 19:08 ian-hutchinson

Hi, I have the same problem as ian-hutchinson, the NEXT_TRANSLATE_PATH is not respected correctly inside nx dev.

My workaround to make it works is to update my environment variable like this:

NEXT_TRANSLATE_PATH=../..

perscrew avatar Nov 27 '23 09:11 perscrew

Please correct me if I'm wrong, won't this part of code var _a = require(path.join(dir, 'i18n')) return a folder instead of a JSON or .js file, regardless of NEXT_TRANSLATE_PATH ? Is is mandatory to have a folder called i18n? I'm having the same problem in a production environment in firebase

vitordhers avatar Feb 05 '24 15:02 vitordhers

I have the same error in my project with nx

image

Same issue. Fixed with @perscrew fix. The path.relative and path.join are not working.

splacentino avatar Feb 16 '24 12:02 splacentino