Comments (5)
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.
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.
I've seen before something like the es6-promise module that exposes a .polyfill()
method to optionally write to globals.
from isomorphic-fetch.
Yes, please! I won't use this module if it pollutes the global, but having the option would be wonderful.
from isomorphic-fetch.
Oh nice!
from isomorphic-fetch.
Related Issues (20)
- Upgrade node-fetch to >= 2.3.0 to fix semantic-release users that use styled-components HOT 2
- Fix version of whatwg-fetch HOT 1
- eiddccgeilvtdejdrvblujinlecirnvcbbnnnunegklr
- AbortController not working with this library HOT 4
- URLSearchParams in body doesn't set content-type to x-www-form-urlencoded
- Is this library still been maintained? HOT 4
- Tag a new version with the security fix HOT 11
- Add v3.0.0 release notes HOT 2
- How to handle error messages from server - Question HOT 1
- Node.js - realFetch.call is not a function HOT 8
- Isomorphic-fetch Typescript setup HOT 2
- Upgrade node-fetch to version 2.6.1 or 3.0.0-beta.9 HOT 1
- fetch api
- update node-fetch to v3.x HOT 7
- Security risk
- Found a possible security concern HOT 2
- Interceptors
- How to access the referer using isomorphic fetch library? An example would help!
- Dual Form
- Isomorphic fetch returns response with empty stream body HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from isomorphic-fetch.