#StackBounty: #javascript #node.js #typeerror TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type Funct…

Bounty: 50

In the following code, I get this error:

TypeError [ERR_INVALID_ARG_TYPE]: The “original” argument must be of type Function. Received type undefined

const sqlite3 = require('sqlite3').verbose();
const util = require('util');

async function getDB() {
    return new Promise(function(resolve, reject) {
        let db = new sqlite3.Database('./project.db', (err) => {
          if (err) {
            console.error(err.message);
                reject(err)
          } else {
            console.log('Connected to the project database.');
                resolve(db)
        }
        });
        return db
    });
}


try {
        // run these statements once to set up the db
        let db = getDB();
        db.run(`CREATE TABLE services(id INTEGER PRIMARY KEY, service text, date text)`);
        db.run(`INSERT INTO services(id, service, date) VALUES (1, 'blah', '01-23-1987')`)
} catch(err) {
    console.log(err)
}


const db = getDB();
const dbGetAsync = util.promisify(db.get);

exports.get = async function(service) {

    let sql = `SELECT Id id,
                                     Service service,
                                    Date date
                        FROM services
                        WHERE service  = ?`;

    const row = await dbGetAsync(sql, [service], (err, row) => {
        if (err) {
                             console.error(err.message);
                             reject(err)
        }
            let this_row = {'row': row.id, 'service': row.service};
            this_row ? console.log(row.id, row.service, row.date) : console.log(`No service found with the name ${service}`);
            resolve(this_row)
    });

    return row;
}

let row = exports.get('blah')

It says the problem is in line 31: const dbGetAsync = util.promisify(db.get);

$ mocha src/tests/testStates.js
C:UsersCodyAppDataRoamingnpmnode_modulesmochanode_modulesyargsyargs.js:1163
else throw err
^

TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type Function. Received type undefined
    at Object.promisify (internal/util.js:256:11)
    at Object.<anonymous> (C:UsersCodyProjectsgoggle-indexersrcstate.js:32:25)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:UsersCodyProjectsgoggle-indexersrcteststestStates.js:7:15)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at C:UsersCodyAppDataRoamingnpmnode_modulesmochalibmocha.js:330:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (C:UsersCodyAppDataRoamingnpmnode_modulesmochalibmocha.js:327:14)
    at Mocha.run (C:UsersCodyAppDataRoamingnpmnode_modulesmochalibmocha.js:804:10)
    at Object.exports.singleRun (C:UsersCodyAppDataRoamingnpmnode_modulesmochalibclirun-helpers.js:207:16)
    at exports.runMocha (C:UsersCodyAppDataRoamingnpmnode_modulesmochalibclirun-helpers.js:300:13)
    at Object.exports.handler.argv [as handler] (C:UsersCodyAppDataRoamingnpmnode_modulesmochalibclirun.js:296:3)
    at Object.runCommand (C:UsersCodyAppDataRoamingnpmnode_modulesmochanode_modulesyargslibcommand.js:242:26)
    at Object.parseArgs [as _parseArgs] (C:UsersCodyAppDataRoamingnpmnode_modulesmochanode_modulesyargsyargs.js:1087:28)
    at Object.parse (C:UsersCodyAppDataRoamingnpmnode_modulesmochanode_modulesyargsyargs.js:566:25)
    at Object.exports.main (C:UsersCodyAppDataRoamingnpmnode_modulesmochalibclicli.js:63:6)
    at Object.<anonymous> (C:UsersCodyAppDataRoamingnpmnode_modulesmochabin_mocha:10:23)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

I’m having problems using this promisify library. Any help appreciated.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.