Promise.reject is not a constructor Error in JavaScript

avatar

Borislav Hadzhiev

Last updated: Oct 19, 2021

banner

Photo from Unsplash

Promise.reject is not a constructor Error in JavaScript #

The "Promise.reject is not a constructor" error occurs when we try to use the Promise.reject() method with the new operator. The Promise.reject() method is not a constructor so it should be used without the new operator, e.g. Promise.reject('err').

promise reject is not a constructor

Here's an example of how the error is caused.

index.js
// ⛔️ Promise.reject is not a constructor const err = new Promise.reject(new Error('boom'));

Instead, we should not use the new operator with the Promise.reject method.

index.js
// ✅ works const rejected = Promise.reject(new Error('boom'));

Promise.reject is a method, not a constructor. The only parameter the method takes is the reason why the promise should be rejected.

The Promise.reject() method returns a promise that is rejected with the provided reason.

Note that as opposed to the Promise.reject method, Promise() is a constructor which is used to wrap functions that don't already support promises.

The following 2 examples achieve the same result:

index.js
const r1 = Promise.reject(new Error('boom')); const r2 = new Promise((resolve, reject) => { reject(new Error('boom')); });

Both of the examples return a promise that is rejected with the provided reason, however the Promise.reject method provides us with a more direct and concise solution than the Promise() constructor for this use case.

Conclusion #

The "Promise.reject is not a constructor" error occurs when we try to use the Promise.reject() method with the new operator. The Promise.reject() method is not a constructor so it should be used without the new operator, e.g. Promise.reject('err').

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.