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.

Consider adding back browser field in v3

See original GitHub issue

v3 removed the browser field, but I believe this should be reconsidered.

The recommended alternative to use cross-fetch is not ideal. Since cross-fetch ships as a ponyfill, any usage via import (import fetch from "cross-fetch") will cause webpack to include an unnecessary cross-fetch ponyfill in the bundle for environments with native fetch.

Scenario: A user is bundling using webpack and depending on an SDK library that uses fetch internally. The SDK library is intended to support both node and modern browsers. Which fetch package should the SDK library use?

  • node-fetch v2: Webpack includes browser.js from node-fetch which is a tiny wrapper around the native fetch
  • node-fetch v3: Webpack includes src/index.js which is not intended to be used in the browser
  • cross-fetch: Webpack includes the entire whatwg-fetch ponyfill and it will be used instead of native fetch

Removing browser.js from this package leaves no way for the SDK library to support modern browsers without also forcing unnecessary code in the end-user bundle

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
gr2mcommented, Apr 26, 2020

Also strong negative from me. The "browser" key was never standardized. It’s a made-up key that most JS bundlers adopted, but not consistently. I cannot count the hours of maintenance pain that the “browser” field caused for obscure use cases. It might make your life easier if node-fetch added it, but it’s a gateway to maintenance hell.

Node.js now created a standard that will be a much better fit to server different code for different environments: conditional exports. But to my knowledge none of the bundlers adopted the standard yet.

3reactions
bitinncommented, Apr 24, 2020

Strong negative, node-fetch is never intended for browser side, you are your best judge as to what polyfill / global export / global fetch is acceptable, we should not be the judge.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Field 'browser' doesn't contain a valid alias configuration
I tried adding a browser field to my package.json but that didn't seem to do any good. webpack.config.js import path from ' ...
Read more >
How To Create A Browser Back Button In Divi
In this tutorial I will show you how to use a normal Divi Button module as a browser back button to always go...
Read more >
Focus Order - Understanding Success Criterion 2.4.3 - W3C
2.4.3 Focus Order: If a Web page can be navigated sequentially and the navigation sequences ... they are added or removed from the...
Read more >
Using HTTP cookies - MDN Web Docs
The browser may store the cookie and send it back to the same ... Cookies from the same domain are no longer considered...
Read more >
Web browser - Wikipedia
A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves...
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