Skip to content
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

feat: add possibility to define next-i18next.config as json file #1384

Closed
wants to merge 5 commits into from
Closed

Conversation

adrai
Copy link
Member

@adrai adrai commented Aug 30, 2021

This will help when using next-i18next (simple configurations only) with Next.js >= 10.2.x and prevents the issue #1202

@vercel
Copy link

vercel bot commented Aug 30, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/isaachinman/next-i18next/CjhujYUC9Cu9MEmpHJGpNdTtwA9B
✅ Preview: https://next-i18next-git-fork-adrai-master-isaachinman.vercel.app

@adrai adrai changed the title add possibility to define next-i18next.config as json file feature: add possibility to define next-i18next.config as json file Aug 30, 2021
@adrai adrai changed the title feature: add possibility to define next-i18next.config as json file feat: add possibility to define next-i18next.config as json file Aug 30, 2021
@isaachinman
Copy link
Contributor

Can we use a require instead, to avoid this issue entirely?

@adrai
Copy link
Member Author

adrai commented Aug 31, 2021

Can we use a require instead, to avoid this issue entirely?

unfortunately no... it behaves the same as import

@isaachinman
Copy link
Contributor

Sorry, currently out of office – is there an issue on the NextJs repo to track this?

@adrai
Copy link
Member Author

adrai commented Aug 31, 2021

Sorry, currently out of office – is there an issue on the NextJs repo to track this?

no rush...

It's still the same issue as described in #1202 and based on Next.js it's by design, so no issue 🤷‍♂️ vercel/next.js#25077

https://nextjs.org/docs/advanced-features/dynamic-import
image

@isaachinman
Copy link
Contributor

If this is an intentional choice by the Vercel team, then I'd prefer to fix this in the "right" way. Can't we hardcore the config path to satisfy that requirement?

@adrai
Copy link
Member Author

adrai commented Aug 31, 2021

If this is an intentional choice by the Vercel team, then I'd prefer to fix this in the "right" way. Can't we hardcore the config path to satisfy that requirement?

If you know how, without any errors....

@adrai
Copy link
Member Author

adrai commented Sep 7, 2021

@isaachinman any idea on how to hardcode the config so this could work?

@isaachinman
Copy link
Contributor

isaachinman commented Sep 7, 2021

Can we use a require instead, to avoid this issue entirely?
unfortunately no... it behaves the same as import

How can that be true? Are you saying that with webpack 5, all NodeJs requires are broken if they use a variable or template literal?

@adrai
Copy link
Member Author

adrai commented Sep 7, 2021

userConfig = await import('./next-i18next.config.js')

Will not work, because relatively that file really does not exist. btw: also the build step is erroring:

src/serverSideTranslations.ts:51:33 - error TS2307: Cannot find module './next-i18next.config.js' or its corresponding type declarations.

51       userConfig = await import('./next-i18next.config.js')

Regarding the require... it behaves exactly the same as await import...
So these 2 variants are the same:

userConfig = await import(path.resolve(`${DEFAULT_CONFIG_PATH}.js`))
userConfig = require(path.resolve(`${DEFAULT_CONFIG_PATH}.js`))

I tried everything... 😢

@isaachinman
Copy link
Contributor

I haven't had a chance to deep dive into webpack 5 yet, but I assume there must be a way of designating true NodeJs entry points via package.json or similar, so that webpack won't attempt these optimisations and won't hijack require.

@isaachinman
Copy link
Contributor

Apologies again, my time has been really limited lately.

Calling for help on this one – there must be other packages in the NextJs ecosystem that rely on config files.

@martpie @HaNdTriX @Timer @ijjk Any advice?

@isaachinman
Copy link
Contributor

@adrai Well, failing any first-class solution, something like this should work:

userConfig = eval(fs.readFileSync(path.resolve(DEFAULT_CONFIG_PATH), 'utf-8'))

@adrai
Copy link
Member Author

adrai commented Sep 19, 2021

@adrai Well, failing any first-class solution, something like this should work:

userConfig = eval(fs.readFileSync(path.resolve(DEFAULT_CONFIG_PATH), 'utf-8'))

Unfortunately this would not work if the config includes some require statement... 😥
i.e. when using other i18next backends

@isaachinman
Copy link
Contributor

And how would that use case be supported by a JSON file?

@adrai
Copy link
Member Author

adrai commented Sep 19, 2021

And how would that use case be supported by a JSON file?

Not at all, that's why I was thinking of making it clear with a JSON file 🤷‍♂️

@adrai
Copy link
Member Author

adrai commented Sep 19, 2021

Do you have some direct connection to the Next.js team to ask for their advice?

@isaachinman
Copy link
Contributor

@adrai Whatever solution we decide on should work regardless of a user's specific requirements.

Do you have some direct connection to the Next.js team to ask for their advice?

Yes, I'll ping them via Slack.

@isaachinman
Copy link
Contributor

@adrai I was told it sounds related to this issue, which is actively being worked on: vercel/next.js#24700

@adrai
Copy link
Member Author

adrai commented Sep 27, 2021

@adrai I was told it sounds related to this issue, which is actively being worked on: vercel/next.js#24700

I'm already subscribed to that issue ;-)
I've also tried 11.1.3-canary.33 with experimental nftTracing=true but no luck :-(

@adrai
Copy link
Member Author

adrai commented Oct 2, 2021

fyi: tried also with 11.1.3-canary.41 and the new experimental property outputFileTracing 😢

@adrai
Copy link
Member Author

adrai commented Oct 20, 2021

Seems to be only an issue if linking next-i18next: #1202 (comment)

@adrai adrai closed this Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants