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.

Build fails with Vite and other rollup-based bundlers

See original GitHub issue

🐛 Bug Report

Vite is a blazingly fast bundler and is being increasingly used amongst devs. I’ve recently gotten the product team at our company to use it more because webpack-dev-server can get extremely slow for large projects.

In production mode, Vite uses rollup internally to bundle code. The problem is, it seems that this library specifically is causing builds to fail with runtime errors on initial load.

To save you some time, I’ve already done a little bit of research and figured out the root of this problem. node-fetch is somehow being bundled into the browser in rollup. Thus the runtime errors are from trying to access non-existent node libs in the browser.

To Reproduce

Pull from this test repo: https://github.com/diracs-delta/i18next-http-backend-rollup-demo

And then run

yarn
yarn vite build && yarn vite preview

and navigate to localhost:5000.

Expected behavior

i18next plugins should be compatible with the latest bundlers and not sometimes import node-fetch on accident.

Your Environment

  • runtime version: node 15, any
  • i18next version: see package.json
  • os: Mac

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dlqqqcommented, May 12, 2021

I moved the conditional within the if statement to a console log, which returned false. VIte might not be optimized enough to detect that, and is still trying to bundle node-fetch. Nevertheless, I think you are right. A dynamic import is not the answer. I truthfully don’t know enough about CJS to understand what’s actually going on here.

I’ll reach out to Vite and link them this issue, but it might be worth considering using cross-fetch instead of trying to re-invent the wheel here. cross-fetch seems to work just fine on Vite, so if it isn’t too much of a change, perhaps i18next-http-backend could switch to using cross-fetch?

0reactions
dlqqqcommented, May 12, 2021

@adrai It’s fixed! Thank you so much! We can use i18next in our production builds now. I’ll let the Vite community know that this update will fix their builds. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

i18next-http-backend production problem #2045 - vitejs/vite
The problem appears to be with this package i18next-http-backend... in production this package ... Build fails with Vite and other rollup-based bundlers ......
Read more >
Troubleshooting - Vite
If you are using Linux, file descriptor limits and inotify limits may be causing the issue. As Vite does not bundle most of...
Read more >
Vite: Rethinking Frontend Tooling by Evan You - GitNation
Vite is a new build tool that intends to provide a leaner, faster, ... and a production bundler, which is Rollup-based, it's pre-configured, ......
Read more >
Vite - A No Bundler Build Tool | Quinbay - Medium
Another popular Vue dev server, Vue CLI is built on top of webpack. ... Vite fails to create bundles when it comes to...
Read more >
Svelte.js 3 & The Vite Build Tool Tutorial - KoderHQ
Learn how to use Vite to initialize new Svelte projects. ... A pre-configured Rollup -based production bundler that produces highly optimized builds.
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