# Promises: Ember.RSVP is not a constructor

**URL:** <https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505>\
**Category:** Learning Team\
**Created:** [January 14, 2021, 6:10pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505 "2021-01-14T18:10:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cgallo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/cgallo/32/16157_2.png) [@cgallo](https://discuss.emberjs.com/u/cgallo)\
**Post date:** [January 14, 2021, 6:10pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/1 "2021-01-14T18:10:38Z")

</div>

I am experimenting with Promises and trying to adapt a javascript Promise example I found to Ember. I’m getting this error in the console.

> developer-sandbox.js:34 Uncaught TypeError: Ember.RSVP is not a constructor at DeveloperSandboxController.roll (developer-sandbox.js:34)

Here is what I have in my controller. I get the feeling I’m missing something important.

```
import Controller from '@ember/controller';
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import Promise, { resolve, reject } from "rsvp";

export default class DeveloperSandboxController extends Controller {

...

    dieToss() {
        return Math.floor(Math.random() * 6) + 1;
    }

    @action
    roll() {
        console.log("One");

        let rollTheDie = new Promise(function(resolve, reject) {
            let n = this.dieToss();
            if (n === 6) {
                resolve(n);
            } else {
                reject(n);
            }
        });

        rollTheDie.then(function(toss) {
            console.log('Your rolled a ' + toss + '.');
        }, function(toss) {
            console.log('Unfortunately, you rolled a ' + toss + '.');
        });

        console.log("Two");
    }

```

UPDATE: If I don’t import Promise and move the function inside the action, it works. But, then I’m not using Ember, right?

Thanks for looking. Any help will be appreciated.

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [January 14, 2021, 6:28pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/2 "2021-01-14T18:28:58Z")

</div>

In spite of what the Ember docs seem to say (I just checked) I think you should import Promise as one of the destructured exports rather than the default export:

```auto
import { Promise, resolve, reject } from "rsvp";

```

---

<div class="post-metadata">

**Author:** ![cgallo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/cgallo/32/16157_2.png) [@cgallo](https://discuss.emberjs.com/u/cgallo)\
**Post date:** [January 14, 2021, 7:15pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/3 "2021-01-14T19:15:09Z")

</div>

Thank you. That does clear up the error. But, if it works with or without the import, what do I gain by importing Promise?

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [January 14, 2021, 7:23pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/4 "2021-01-14T19:23:46Z")

</div>

My guess is that without the import you’re getting the native Promise and with the import you’re getting RSVPs Promise. For more reading on that subject see this [nice explanation](https://discuss.emberjs.com/t/readers-questions-why-does-ember-still-use-rsvp). It’s probably safe to just use the native Promise FWIW.

---

<div class="post-metadata">

**Author:** ![cgallo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/cgallo/32/16157_2.png) [@cgallo](https://discuss.emberjs.com/u/cgallo)\
**Post date:** [January 14, 2021, 7:24pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/5 "2021-01-14T19:24:31Z")

</div>

Thanks, again. I’ll read the explanation.

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [January 14, 2021, 7:25pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/6 "2021-01-14T19:25:20Z")

</div>

If you support IE you may not want to use native Promises [based on the MDN page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) (I can never remember all the compatibility stuff).

---

<div class="post-metadata">

**Author:** ![Deepak\_Negi\_Sunny](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@Deepak\_Negi\_Sunny](https://discuss.emberjs.com/u/Deepak_Negi_Sunny)\
**Post date:** [February 22, 2022, 4:40am UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/7 "2022-02-22T04:40:47Z")

</div>

This will raise SonarLint Code smell. Any help here

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [February 22, 2022, 3:22pm UTC](https://discuss.emberjs.com/t/promises-ember-rsvp-is-not-a-constructor/18505/8 "2022-02-22T15:22:33Z")

</div>

Can you be more specific? What’s the issue? And what does the code look like?
