-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
Usage example for ESM #2185
Comments
After changing import to: import { serverSideTranslations } from "next-i18next/dist/esm/serverSideTranslations"; It shows another error:
|
Looks like this module doesn't use "exports" field, and "module" field is not supported officialy: "module" was a rejected proposal, AFAIK: |
I suspect also having an exports field would not fix the problem... If you know of a solution that will work for all environments feel free to provide a PR... I was not able to solve this :-( |
This also might be the reason: When importing next-i18next/serverSideTranslations it always uses commonjs format |
no, I also tried to change that... the main problem is that Next.js wants the exports to be with .mjs ending... and that does not work with modules imported conditionally for browser order node.js side... |
Ah, I seee. So far I've tried lots of options, including (putting here for reference): Forcing mainFields (looks like it is already by default) ref: config.resolve.mainFields = isServer
? ["module", "main"]
: ["browser", "module", "main"]; Making package external (just to test): config.externals = [...config.externals, "next-i18next"]; Directly including the file: import { serverSideTranslations } from "next-i18next/dist/esm/serverSideTranslations.js"; Rewriting alias: config.resolve.alias = {
...config.resolve.alias,
"next-i18next$": "PATH_TO_MODULE/dist/esm/index.js",
}; So far I haven't found even a workaround, unfortunately. Edit: |
@adrai So does this basically mean that there is no way to use this package from ESM NextJS app? I am still trying to find other options/workarounds, but is there at least a hack to make it working? |
yes, there's a way:
|
@adrai Chaning Sorry, forgot about the simplest option :) Yeah, thanks. BTW, we don't need to change next-i18next.config.js if we simply don't include next-i18next.config.cjs there (duplicating i18n config). |
Though now I have a different issue:
Only occures on initial page load in dev mode, hmr fixes it (basically on any first change error goes away). Will looking into it, probably not related to this ticket. Edit: |
https://github.com/i18next/next-i18next#usetranslation import useTranslation from next-i18next, not from react-i18next |
@adrai thanks, edited comment just in time :) Thanks a lot for your help, though there should be some doc note about ESM. I'll create PR some day later |
I can't get my nextjs app working running on type Module. Does anyone have an example? I run into problems not being able to add the .cjs file to the _App main component or to my next.config file. I tried it all night long and it just doesnt work. Even having a next.config.cjs file in combination with next-i18next.config.cjs and a default path overwrite. I18NEXT_DEFAULT_CONFIG_PATH=./next-i18next.config.cjs I get the error: error - Error: Invalid locale returned from getStaticPaths for /[[...slug]], the locale nl is not specified in next.config.js It just doesn't read my next.config location in the right way. The config file's are in order and do have nl as local. module.exports = { please help me out! |
When you use ESM you get this error:
Relevant issue:
#1505
The text was updated successfully, but these errors were encountered: