i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
452 stars 70 forks source link

cross-fetch leaks to client-side bundle #136

Closed felixmosh closed 7 months ago

felixmosh commented 7 months ago

🐛 Bug Report

cross-fetch is ment to be use only in node env (based on the code here), but when I bundle a client app, this lib is inside the bundle.

To Reproduce

https://pzz539.csb.app/

You can search for cross-fetch in the chrome devtools you will see that it's get bundled.

image

Expected behavior

It should be striped from the browser envs

The problem is in that if condition, bundlers usually replacing typeof window with "object" for browser env (atleast Next.js does), so the deopt of this optimization is the second or condition typeof window.document === 'undefined'

if (typeof require !== 'undefined' && (typeof window === 'undefined' || typeof window.document === 'undefined')) {
  var f = fetchApi || require('cross-fetch')
  if (f.default) f = f.default
  exports.default = f
  module.exports = exports.default
}

Your Environment

adrai commented 7 months ago

landed in v2.5.1