GithubHelp home page GithubHelp logo

Comments (5)

matthew-andrews avatar matthew-andrews commented on May 30, 2024 9

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.

from isomorphic-fetch.

paulmelnikow avatar paulmelnikow commented on May 30, 2024 1

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!

from isomorphic-fetch.

tmcw avatar tmcw commented on May 30, 2024

I've seen before something like the es6-promise module that exposes a .polyfill() method to optionally write to globals.

from isomorphic-fetch.

aredridel avatar aredridel commented on May 30, 2024

Yes, please! I won't use this module if it pollutes the global, but having the option would be wonderful.

from isomorphic-fetch.

aredridel avatar aredridel commented on May 30, 2024

Oh nice!

from isomorphic-fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.