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

avatar

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.

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

Use the search field on my Home Page to filter through my more than 1,000 articles.