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
447 stars 69 forks source link

cross-fetch leaks to client-side bundle #136

Closed felixmosh closed 6 months ago

felixmosh commented 6 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 6 months ago

landed in v2.5.1