Heinrich Smit Heinrich Smit - 1 year ago 108
Javascript Question

How to fix pg-promise error "Promise library must be specified."?

I created a basic API in ExpressJS using pg-promise to interact with my PostgreSQL database. When running it on Windows, it works fine. Then I moved it to Ubuntu 15.04, but it gets the following error when I try to start it:


throw new TypeError("Promise library must be specified.");

Answer Source


Use the source, Luke!

Have a look at the file from the error message:

    if (typeof Promise === 'undefined') {
        // ES6 Promise isn't supported, NodeJS is pre-0.12;
        throw new TypeError("Promise library must be specified.");

The version of Node.js in your Ubuntu distro is very old.


I'd recommend that you upgrade Node.js, use LTS version for example (4.x).

An alternative would be to specify a promise library as instructed on the project's website.

Pro-tip: nvm is a great solution to manage versions of Node.js.


Starting from version 5.6.0 of the library, it no longer supports Node.js 0.10.x and 0.12.x, requiring Node.js 4.x as the new minimum.

As a result, that error has been depreciated, as the library will always successfully default to ES6 Promise, if you do not specify any custom promise library.

And if you try running it under Node.js prior to 4.0, it will throw Minimum Node.js version required by pg-promise is 4.x inside its loader.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download