question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

i18next-express-middleware should not be included to the client bundle

See original GitHub issue

I noticed that the size of my app’s client bundle soared after switching to next-i18next from a custom react-i18next integration. As it turned out, the reason was that i18next-express-middleware ended up included into the bundle, which pulled quite a few other modules and made _app.js grow from 5KB gz to 123KB gz.

I tried wrapping require() in create-i18next-client and next-i18next-middleware into eval locally, but that did not help.

It feels a bit strange that the export of i18n.js contains both a hoc and a middleware – that is hard to three-shake. Can the middleware thing be moved to another file and used in server.js only? I mean somehow like this:

// server.js
const i18n = require("./i18n");
const nextI18NextMiddleware = require("next-i18next/express-middleware");
// ...

(async () => {
  await app.prepare();
  const server = express();
  nextI18NextMiddleware(i18n, app, server);

  // ...
})();

To achieve that, i18n can be an uninitialized instance of the original i18n, which gets initialized when it’s used as an argument. Same for hoc?

import i18nHoc from "next-i18next/app-hoc";
import i18n from "../i18n";

const MyApp = ...;

export default i18nHoc(i18n)(MyApp);

Overall, the idea of exporting a single default object in i18n.js and then importing its fields in server.js and _app.js has compatibility issues with TypeScript (see example app, where server.ts uses import instead of require).

UPD: Wrapping i18next-express-middleware into eval actually helped. Bundle size was not decreasing in my first experiment because there was one more require in my custom middleware that I forgot to eval too.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
isaachinmancommented, Dec 6, 2018

Update: it looks like adding next-i18next to a project will increase your commons chunk by just over 400kb (no gzip). That’s not great, and as I said it’s my top priority now.

0reactions
isaachinmancommented, Dec 9, 2018

Would really appreciate a second opinion so that we can (relatively) safely release v0.9.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

i18next-express-middleware should not be included ... - GitHub
I noticed that the size of my app's client bundle soared after switching to next-i18next from a custom react-i18next integration.
Read more >
Why is i18next-http-middleware defaulting back to fallback ...
The middleware is applied I edited my comment to include the debug output. I am getting a language change but it re changes...
Read more >
First setup help - i18next documentation
​Do you want to bundle the translations with your app?​ ... import Backend from 'i18next-fs-backend'; ... yourOptions should not include backendOptions!
Read more >
How does server side internationalization (i18n) look like? de
You may already know how to properly internationalize a client side application ... If you don't bundle your CLI app in a single...
Read more >
React localization with i18next - LogRocket Blog
To localize a React application using the i18next, we must add the ... Update the src/i18n.js file to include the English and Japanese ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found