How to Fix “Promise resolver undefined is not a function” in Node.js or JavaScript

Creating promises in Node.js or JavaScript is a common way to run an asynchronous task. There’s a gotcha that you need to be aware of: the global Promise object provides a constructor that requires an executor function.

The promise executor is a function accepting two other functions: resolve and reject.

If you’re running into the “Promise resolver undefined is not a function” error, your code may look like this new Promise() instead of new Promise((resolve, reject) => { … }).

Node.js Series Overview

Fixing “Promise resolver undefined is not a function”

When using promises in Node.js or JavaScript, you may create promise instances yourself using new Promise().

When you’re not passing down the executor function for the handling to resolve or reject a promise, your terminal may show an error like this:

Promise resolver undefined is not a function  
      at new Promise (<anonymous>)

The fix is straightforward: you must provide a way to resolve or reject promises:

// Instead of this
const promise = new Promise()

// do this
const promise = new Promise(() => {})  

That will fix the problem. The argument is a function providing two arguments: a resolve and a reject function to handle successful and failing promises.

The example code above omits both parameters (resolve and reject) because they're not used in this simple example.

You can find more details about the Promise object in the MDN docs.


Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.