Comments (10)
Unfortunately in React Native, the workarounds mentioned don't seem to be sufficient. Due to the way React packages JS files assuming they support AMD/CommonJS modularization properly, this library ends up running anyway - even if it isn't required.
from fetch.
just found https://github.com/matthew-andrews/isomorphic-fetch and then https://github.com/matthew-andrews/fetch/blob/master/fetch.js#L3 which has:
if (typeof global !== 'undefined') {
var self = global.self;
}
from fetch.
Yes please use that project instead. #31
from fetch.
I don't want to really use it in isomorphic way - I just have an isomorphic setup. That's a bit of a different thing. (Which is why those projects are not really what I am after)
Ideally require("whatwg-fetch")
would just export what it's offering.
What I ended up doing is:
if (process.env.IS_BROWSER) {
require('whatwg-fetch');
}
Not nice - but works.
from fetch.
Your workaround looks good. I would suggest applying the same conditional to all requires in your app that load libraries that are only useful in browsers.
from fetch.
I will.
As a side note - I would much prefer this style of use
var blafetch = require('whatwg-fetch');
blafetch('/users.html')
.then(function(response) {
return response.text()
}).then(function(body) {
document.body.innerHTML = body
})
or even better
var Fetch = require('whatwg-fetch');
Fetch.get('/users.html')
.then(function(response) {
return response.text()
}).then(function(body) {
document.body.innerHTML = body
})
Maybe for the next major version.
from fetch.
As a side note - I would much prefer this style of use
Perhaps you're missing the point of this project. We're trying to create a polyfill for a future standard feature of browsers. The API for that feature is window.fetch
. We're not trying to create anything more or other than that.
from fetch.
I see.
from fetch.
@billinghamj We welcome a PR that solves this while keeping in mind that the code must also be able to run in a web worker environment. See #239 (comment) for context
from fetch.
@mislav That was the purpose of #252. I'll make a PR for it.
from fetch.
Related Issues (20)
- <!-- MODIFIED_CONTENT_LINKING_COMMENT -->
- TDTcR8wBLadFYRekvobSSswHaj351EDNRT
- 📢 🎉 We’ve made some exciting improvements to our [REST API documentation](https://docs.github.com/en/rest) and we'd love to know what you think about the new layout! Let us know 👇 HOT 1
- Thanks for opening this pull request! A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the [contributing guidelines](https://github.com/github/docs/blob/main/CONTRIBUTING.md). HOT 1
- This repository is moving from the github org HOT 2
- Owner [email protected]
- 2018 license appachie com [email protected]
- Refused to get unsafe header "set-cookie"
- Owner
- changelog is missing for latest releases HOT 1
- File fetching broken since commit 0c1d2b9 HOT 3
- Create a Security Policy HOT 1
- Enable OpenSSF Scorecard Action HOT 3
- `Set-Cookie` headers should not be combined / Support `Headers.getSetCookie()` method
- Hash pin actions used on workflows and enable depenadabot
- code is working in chrome, not in firefox HOT 2
- Overriding feature detection HOT 2
- suggestion to use str.indexOf(searchString) === 0 for better compatibility HOT 2
- UMD Releases don't exist HOT 1
- Linkedin uses status code 999 which leads to RangeError 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 fetch.