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

Customer server with custom path

Open devaquila opened this issue 4 years ago • 5 comments

Hello,

I noticed an issue with a custom server, if the "react app" is not in the root folder. You can see that here : https://github.com/oxid83/simple-next-server

(node:5948) UnhandledPromiseRejectionWarning: Error: Cannot find module '/project_root_path/i18n'

It's just a simple custom server (sampled here : https://nextjs.org/docs/advanced-features/custom-server), and we use the "next-translate" example here : https://github.com/vercel/next.js/tree/canary/examples/with-next-translate

Do you have any ideas on how to fix that please ?

devaquila avatar Jul 01 '21 09:07 devaquila

@devaquila you can fix it with an environment variable indicating the path: NEXT_TRANSLATE_PATH. Is documented here: https://github.com/vinissimus/next-translate#12-how-to-use-next-translate-in-a-mono-repo.

I close the issue. If you still having problems please comment here or reopen it

aralroca avatar Jul 01 '21 10:07 aralroca

@aralroca thanks for you answer :) But it's still the same (NEXT_TRANSLATE_PATH=./with-next-translate in the .env or in the environnement variable) FYI, the sample is updated with this fix

devaquila avatar Jul 01 '21 16:07 devaquila

@devaquila Ok, I reopen. Does it happen only with custom server? Tomorrow I'll try the example, I'm not at my computer right now.

aralroca avatar Jul 01 '21 23:07 aralroca

Ok great. We have not tested without custom server. But if the ReactApp is in the root folder, it's working.

devaquila avatar Jul 02 '21 08:07 devaquila

Hello,

I created a Pull request on your demo repo https://github.com/oxid83/simple-next-server/pull/1 (btw, when i tested, there was an error because of multiple react versions)

I tested to use the .env variable, but it didn't worked well so i used process.chdir() to move process.cwd()

Finally, I propose a modification to the README of next-translate here https://github.com/vinissimus/next-translate/pull/650

Its-Just-Nans avatar Jul 20 '21 15:07 Its-Just-Nans