Solve - Promise.reject is not a constructor Error in JS


Borislav Hadzhiev

Tue Oct 19 20211 min read

Solve - Promise.reject is not a constructor Error #

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.

// โ›”๏ธ 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.

// โœ… 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:

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 a more direct and concise solution than the Promise() constructor for this use case.

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee