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.

Feature request: be a normal package

See original GitHub issue

Munging the global state may be true to the spec, but it goes above and beyond how most people develop Javascript. Most front-end and back-end development is done with require() these days, and I think more people will be accustomed to using var fetch = require('isomoprhic-fetch') than would be comfortable using a global variable, much less than the number of people who understand what particular incantations you’ve invoked on behalf of the user to get the global state isomorphically munged like you do.

It’s absolutely ok to provide a built in helper that munges the global state, adding fetch, but that should be a helper, not the default and only way to use this very fine package.

Issue Analytics

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

github_iconTop GitHub Comments

9reactions
matthew-andrewscommented, Oct 20, 2015

I recognise the need for this but my team does not have this need and it would be a backwards incompatible change.

isomorphic-fetch is actually very, very, very small. All it does is merge together node-fetch and GitHub’s Fetch polyfill so that the former is pulled in when you run require('isomorphic-fetch') on the server, and the latter on the client. isomorphic-fetch is mostly config, there’s barely any code at all.

The reason why the isomorphic-fetch library exists is because in the past node-fetch didn’t exist and this module used to provide the server side implementation. Now that node-fetch does exist, this module more or less blindly passes node-fetch through if you require('isomorphic-fetch') on the server.

I maintain isomorphic-fetch largely for backwards compatibility for old projects.

If I were to create a brand new project today I’d probably use the GitHub fetch polyfill on the client side directly (or with the polyfill service) and node-fetch directly in Node.

If someone wanted to fork isomorphic-fetch and got rid of the defining-itself-globally behaviour I would gladly link to that in the README.md of this module. I’d suggest calling it safe-isomorphic-fetch or perhaps universal-fetch.

I don’t really want to maintain to different versions of isomorphic-fetch so for this issue I will say no. Sorry.

1reaction
paulmelnikowcommented, May 22, 2016

I had a similar need to the original poster, and I assembled a proof of concept which mashed up the best of isomorphic-fetch and fetch-ponyfill. I got great results in Browserify, Webpack, and Node.

Rather than publish a new package right off the bat, I approached @qubyte to see if I could add what I needed to fetch-ponyfill

From qubyte/fetch-ponyfill#2 and qubyte/fetch-ponyfill#3:

I’ve got a proof of concept of a version of this which does not depend on brfs and is also agnostic of webpack. I adapted the clever approach you took here, of patching whatwg-fetch without vendoring in the source. But instead of doing it at compile time, I did that in a build step, and checked in the result.

It’s a little bit gross to check in the generated code, but I like that it’s a bundler-agnostic solution. Agnosticism is a good thing. An ecosystem of opinionated packages leads to JavaScript fatigue, which is something I’m feeling pretty heavily these days.

To me, checking in a generated CommonJS module seems like a reasonable compromise for bundler agnosticism, though I’m curious your thoughts.

I need a Node + Webpack ponyfill for my current project, but I haven’t found one of those – hence building this POC – and I’d rather use something that is Browserify-compatible too. My team is trying out webpack, mostly for hot loading, but hasn’t really settled on it in the long term. I know there are some hot-loading solutions for Browserify now. Really, just trying to stay agnostic.

Would you be interested in taking a look at it and seeing if you’d like to incorporate it into this project? If you’d like to incorporate it here, I can avoid publishing a new project (and adding marginally to everyone else’s JS fatigue). If not, I certainly have no problem publishing it separately.

I’m pleased to say that has all been merged, so you can now use this in Node or the browser:

var fetch = require('fetch-ponyfill')();

Or, provide a Promise implementation, to support older browsers and older Node environments:

var Promise = require('promise');
var fetch = require('fetch-ponyfill')({ Promise: Promise });

Hopefully you’re still up for adding a link to the readme! I’ll open a PR.

P.S. I did look around for other working solutions before implementing this. There is a package called universal-fetch, but it’s a fork of this repo that supports IE8, and still a polyfill. And, by the way, thanks for the clear “wontfix” in this thread!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle feature requests that add new package ...
I am the maintainer of a package on hackage, lrucache. I recently received a feature request for adding instances for Binary and NFData...
Read more >
7 Useful Tips to Manage Feature Requests - Craft.io
Feature requests can provide product managers with great ideas for product improvement, but they must be managed correctly. Here are our top tips....
Read more >
Feature Requests: What are they and how to manage them
Feature requests are a form of product feedback you may frequently encounter as a SaaS product manager. They typically come in the form...
Read more >
10 Tips for Responding Graciously to Customer Feature ...
10 Tips for Responding Graciously to Customer Feature Requests · 1. Be open and honest · 2. Be grateful for their effort ·...
Read more >
Feature Requests - ShippingEasy
We would like to assign specific SKUs to a dedicated user to be able to run reports and perform any updates needed for...
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