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:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\node_modules\yargs\yargs.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:\Users\Cody\Projects\goggle-indexer\src\state.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:\Users\Cody\Projects\goggle-indexer\src\tests\testStates.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:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:330:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:327:14)
at Mocha.run (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:804:10)
at Object.exports.singleRun (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\lib\cli\run-helpers.js:207:16)
at exports.runMocha (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\lib\cli\run-helpers.js:300:13)
at Object.exports.handler.argv [as handler] (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\lib\cli\run.js:296:3)
at Object.runCommand (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\node_modules\yargs\yargs.js:1087:28)
at Object.parse (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\lib\cli\cli.js:63:6)
at Object.<anonymous> (C:\Users\Cody\AppData\Roaming\npm\node_modules\mocha\bin\_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.
I got this error because I was using an old Node version (8.17.0), updating Node to a newer version (12.14.0) fixed this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With