next-translate
next-translate copied to clipboard
Can not find module i18n
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?
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
Did you add i18n config file following this guide?
@chanphiromsok would be great to know more details about your project. Maybe is something missing like i18n.js
file. Thanks
I follow the guide for nextjs 13 app directory also have config file i18n.js and locales folder in the root directory
@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!
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.
I have the same error in my project with nx
@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 😅
@ilchenkoArtem how did you solve TS errors when running NX composePlugins
?
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).
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=../..
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
I have the same error in my project with nx
Same issue.
Fixed with @perscrew fix. The path.relative
and path.join
are not working.