Friday, 5 May 2017

Node.js * is not a constructor when requiring an NPM package

I am working on a Sails.js project that requires me to use this NPM package. I created a new Sails.js service to invoke this package after npm install-ing it like this:

// Require and initialize the rules engine
var jsonRulesEngine = require('json-rules-engine'),
    rulesEngine = new jsonRulesEngine();

When I run this script, I get the following error:

/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/async.js:61
        fn = function () { throw arg; };
                           ^

TypeError: jsonRulesEngine is not a constructor
    at Object.verify (/Users/Nag/Code/learn-nodejs/server/api/services/RulesService.js:21:27)
    at Object.wrapper [as verify] (/Users/Nag/Code/learn-nodejs/server/node_modules/@sailshq/lodash/lib/index.js:3250:19)
    at /Users/Nag/Code/learn-nodejs/server/api/controllers/UtilsController.js:113:43
    at /Users/Nag/Code/learn-nodejs/server/api/services/RedisService.js:55:13
    at tryCatcher (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise.successAdapter [as _fulfillmentHandler0] (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/nodeify.js:23:30)
    at Promise._settlePromise (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/promise.js:566:21)
    at Promise._settlePromise0 (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/Nag/Code/learn-nodejs/server/node_modules/bluebird/js/release/async.js:17:14)
    at Immediate.<anonymous> (/Users/Nag/Code/learn-nodejs/server/node_modules/async-listener/glue.js:188:31)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)
[nodemon] app crashed - waiting for file changes before starting...

Any clue why I might get that error? In the examples section of the package, the owner of the package imports the package using ES6 format whereas I am requiring it. Does that make a difference? Thank you.



via Nag

No comments:

Post a Comment