Axios with promise.prototype.finally doesn't work
Solution 1
Try one of these see if it works:
See if you have a global Promise available to shim it? Enter
Promise
in chrome console while the browserify is running the bundle. If you don't have it, use Babel or a lib that makes es6 or just Promise available.If it didn't work for some reason... well axios cookbook.md didn't get it right, since you have to call shim() to apply it on promise proto. why don't you use a shorthand
require('promise.prototype.finally').shim();
if you don't like it that way, otherwise you have torequire('es6-shim');
Solution 2
FYI https://github.com/axios/axios/issues/34#issuecomment-558869934
Axios supports .finally()
.
Comments
-
JC Lee almost 2 years
Not sure what I am missing. Following the instructions here: https://github.com/mzabriskie/axios/blob/master/COOKBOOK.md
I have npm installed both axios and
npm install axios promise.prototype.finally --save
.I am using Gulp with Browserify.
var axios = require('axios'); require('promise.prototype.finally'); axios.get('http://google.com').finally(function(){ console.log('test'); });
Error:
app-7ee90adab7.js:18780 Uncaught TypeError: axios.get(...).finally is not a function
Update: This makes it work but do I need to do this?
var promiseFinally = require('promise.prototype.finally'); promiseFinally.shim();
-
JC Lee over 7 years1. Promise does return
function Promise() { [native code] }
but browserify is used in a gulp task. I am not sure if you mean browserify in the browser. 2. I went with the shorthand. -
noblerare almost 6 yearsHm, this doesn't seem to work for me. I've installed
promise.prototype.finally
and used the shorthand in the answer above but get the errorProperty 'finally' does not exist on type Promise<void>