2

I have included Bluebird like so...

<script src="../../js/libs/bluebird.min.js" type="text/javascript"></script>

When I run the following code...

requestEvent(request, src)

        .then(function (response) {

            ...
        })
        .finally(function () {

            ...
        });

function requestEvent(request, src) {

    return new Promise(function (resolve, reject) {

        $.ajax({
            url: 'mywebsite',
            type: "POST",
            success: function (response) {

                if (response.status == 0) {

                    reject(response.message);
                }

                resolve(response);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                reject(XMLHttpRequest.responseText);
            }
        });
    });
}

I get...

TypeError: requestEvent(...).then(...).finally is not a function

Why does finally not exist?

This is client/browser code.

Liam
  • 27,717
  • 28
  • 128
  • 190
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
  • 2
    It feels that you didn't use `installation` section from the docs, and using native `Promise` on instead of bluebird. Have you done [this](http://bluebirdjs.com/docs/install.html#browserify-and-webpack)? – Andrey Sep 22 '17 at 14:44
  • I'm not using node. – Ian Warburton Sep 22 '17 at 14:45
  • 1
    Check your script path, I tested and it works fine, check this out https://jsbin.com/labixiwiru/edit?html,js,console,output – AngelSalazar Sep 22 '17 at 14:48
  • I have two pages and was testing it from the one without a script reference. – Ian Warburton Sep 22 '17 at 14:51
  • I'd suggest you delete your question since it is no longer on-topic for stack overflow and there is no reason for people to read and try to answer the question. Deleting it will also avoid an accumulation of downvotes. – jfriend00 Sep 22 '17 at 17:21
  • Not all browsers support the Promise.prototype.finally() method. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally – vivanov Feb 11 '18 at 19:03
  • need to add `const Promise = require("bluebird")` at top of code to use bluebird Promise instead of default one. – azhar22k Apr 02 '18 at 05:51
  • 1
    Do not delete this question, it was the top google hit and help resolve my issue. – Aaron McMillin Jul 04 '18 at 15:43

1 Answers1

3

finally() is not a function for a promise

Read this : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

You need to check if the path of bluebird is correct or not.

Update 2018: .finally() is now (TC39 stage 4; finished) part of the official specification now as you can see in the same link above or in this specific page. However not many browsers support it yet.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415