Comments (32)
+1 for allowing me to change the promise implementation.
from axios.
@CrisLi I solved the issue by checking if Promise attribute is in the global scope, otherwise, window.Promise =BluebirdPromise;
from axios.
I'm 👍 on removing the promise from the library. I would even go as far as not specifying it as a peerDependency. I'm with facebook's on this one:
https://facebook.github.io/react/docs/working-with-the-browser.html#browser-support-and-polyfills
we've also taken the stance that we, as authors of a JS library, should not be shipping polyfills as a part of our library. If every library did this, there's a good chance you'd be sending down the same polyfill multiple times, which could be a sizable chunk of dead code.
from axios.
0.6.0 has released, and in the upgrade guide, only es6-promise has been mentioned.
require('es6-promise').polyfill();
var axios = require('axios');
How to config axios using bluebird?
from axios.
One possible approach could be something similar to:
https://github.com/spoike/refluxjs#switching-promise-library
from axios.
+1 for possibility to switch promise implementation, using native-promise-only in many projects, this would reduce the bundle size.
from axios.
In webpack or browserify, alias the package to:
axios/dist/axios.standalone.js
It will be prebuilt, but it won't require a separate promise. Promise
must be defined globally.
from axios.
Oops, just tried it and the standalone build still assumes Promise.polyfill exists.
from axios.
@torarnek why do you want to use your own Promise lib? The idea behind using es6-promise
is that since it's just a poyfill, I can drop the dependency in the future once all browsers support it natively. In the mean time any browser that already supports native Promises will use the native implementation.
from axios.
@hoppula axios is already using native Promise if it exists. If you're just trying to reduce the bytes, you can use dist/axios.standalone.js
which doesn't bundle Promise.
from axios.
I'm using babel and its runtime. Calls to Promise are swapped with babel-core's Promise. So I already have something taking care of polyfilling.
from axios.
@pstoica sounds like a bug. Shouldn't be calling Promise.polyfill
when standalone.
from axios.
Sounds good. How about making a __STANDALONE__
flag with DefinePlugin to remove that?
from axios.
Would also be interested in this. I'm using browserify and would like to use bluebird as the promise implementation for axios since it supports finally
.
from axios.
@pstoica standalone build is fixed with 0.5.1
from axios.
Great, thanks so much! Seems like this can be closed now?
from axios.
I'm using browserify. require('axios/dist/axios.standalone')
just returns an empty object?
from axios.
@kentor the files under dist/
are meant for either global <script src="axios/dist/axios.js"></script>
or for use with AMD require(['axios'], function (axios) {});
.
For CJS there currently isn't an option, which is where I think this issue is stemming from.
If you want bluebird just to use finally
I would recommend looking at this recipe.
from axios.
It sounds like browserify is picking up the file fine. Wouldn't one UMD build fix all these issues? (I didn't realize axios.js was one var declaration.)
from axios.
Thanks @mzabriskie, standalone build works great with browserify after the fix.
@kentor you should just require('axios')
and then in your package.json
:
really late edit: @kentor you're right, my build hadn't been properly updated, can confirm that it just returns an empty object.
from axios.
@hoppula that work for you? I tried it and it's the same, I just get a {}
. I think specifying an alias in the browser field is basically the same as explicitly calling require('axios/dist/axios.standalone.js')
.
@mzabriskie thanks that recipe does work indeed. Though, I guess I will need to use the same promise implementation as the one in axios in other places in my code if I want to save bytes in my bundle.
from axios.
You're getting an empty object because nothing is being exported yet. One UMD build will give you either AMD, CommonJS, or a global. It also means you wouldn't have to specify AMD/etc in the filename.
from axios.
I have reworked the bundling to be UMD compatible. While this will allow requiring dist/axios.standalone.js
using CJS I have a couple reservations about moving forward with this.
- UMD falls apart under specific conditions. Let's assume we're working in a legacy system, where everything is dumped onto global. In an effort to clean things up we introduce requirejs and start pulling in dependencies with AMD. In any sizable app this cannot be done overnight, so we have a migration strategy, and start converting things over time. As soon as requirejs is on the page any UMD module is immediately unavailable globally. So hypothetically if we wanted to keep axios global until all our project was migrated to AMD, then using UMD for axios just broke the app. The reason for this is that UMD does a test like
if(typeof define === 'function' && define.amd)
. Even if we are loading our UMD module with a script tag, it's going to use the AMD loading strategy. - In order to save bytes in the browser, everything under
dist/
ignores the node code path. It is assumed that if you are using node you will just be doingvar axios = require('axios');
and there will be no need for a bundled module as is needed in the browser. This means that even though UMD will support use with CJS, doingvar axios = require('axios/dist/axios.standalone');
will try and use the XHR adapter, not HTTP as expected. So you're still stuck using the polyfilled Promise.
I would prefer using UMD as it simplifies dist/
, and greatly simplifies the build. At the same time I don't want to do it at the cost of introducing new headaches.
from axios.
Can you not just not require es6-promise (by default instead of in the global build) and add something to the readme telling the consumer to use babel or es6-promise?
from axios.
@nelix that would be preferable in a lot of ways. We could switch es6-promise to be a peerDependency, then it's readily available if needed.
Anyone else have any opinions on this? It would not be backward compatible, which I'm okay with. This could be communicated with an upgrade guide. The biggest factor is just pushing off the Promise dependency management to the developer consuming axios. At the same time, it allows more flexibility.
from axios.
Yeah, I think at this point it'd be better to ask people to responsibly manage their own Promise/ES6 polyfills. I think people would be using Promises in general if they decided to use axios.
from axios.
+1 to remove polyfills from library.
from axios.
Please make axios use standard finally
:)
from axios.
👍 on removing es6-promise from the library.
from axios.
Once 0.6.0 has been released you will need to provide your own promise implementation.
from axios.
@CrisLi have you found out how to configure axios to rely onBluebird as promise library?
from axios.
Sorry, I have switched to use Fetch API.
from axios.
Related Issues (20)
- Integrate into Google OSS Fuzz
- ERROR "TypeError: Streaming request bodies is not supported" seems to have a route in axios HOT 2
- How does Axios handles mTLS requests? HOT 1
- Fetch adapter lost session in cross-domain HOT 2
- Response interceptor doesn't run on small timeout
- Params are ignored for GET requests when headers are present HOT 4
- Access streamed text from "onDownloadProgress" using fetch adapter
- readablestream illegal constructor
- Executing a request with a large body is abnormally slow
- Add ECONNREFUSED error code to AxiosError typings
- Axios should warn about options like `baseURL` being misspelled `baseUrl` HOT 1
- Additional parameter added to a response HOT 2
- Axios is not setting content-length automatically for each part during multi-part file upload using formdata
- CORS policy blocked
- Feature Request: extending request config
- java,security.cert,CertPat hValidatorException: Trust PR MASER
- React Native app works fine on ios but Axios network request in android HOT 2
- Axios returns 400 with application/x-www-form-urlencoded HOT 1
- Cookies are lost when capturing packets with Fiddler. HOT 1
- No Upload Progress Safari
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 axios.