Axios with promise.prototype.finally doesn't work

18,183

Solution 1

Try one of these see if it works:

  1. 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.

  2. 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 to require('es6-shim');

Solution 2

FYI https://github.com/axios/axios/issues/34#issuecomment-558869934 Axios supports .finally().

Share:
18,183
JC Lee
Author by

JC Lee

Building stuff. Need help starting up? Contact me now!

Updated on June 05, 2022

Comments

  • JC Lee
    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
    JC Lee over 7 years
    1. 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
    noblerare almost 6 years
    Hm, 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 error Property 'finally' does not exist on type Promise<void>