2

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:

/node_modules/pg-promise/lib/promise.js:46

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

Community
  • 1
  • 1
Heinrich Smit
  • 68
  • 1
  • 9

1 Answers1

2

problem

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.

solution

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.

update - 1

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.

update - 2

Version 6.7.0 and later require Node.js 4.5.0 as the minimum.

vitaly-t
  • 24,279
  • 15
  • 116
  • 138
Mehdi
  • 7,204
  • 1
  • 32
  • 44
  • 1
    Thanks!! The mistake I made was that I used apt-get to install node, so the version was 0.10. I'll definitely use nvm from now on. Also, you're 100% right. Looking through the source should be step 1 in troubleshooting process. – Heinrich Smit Jun 03 '16 at 08:00