gpt4 book ai didi

javascript - TypeError [ERR_INVALID_ARG_TYPE] : The "original" argument must be of type Function. 接收类型未定义

转载 作者:数据小太阳 更新时间:2023-10-29 04:12:10 24 4
gpt4 key购买 nike

在下面的代码中,我得到了这个错误:

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')

它说问题在第 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)

我在使用这个 promisify 库时遇到问题。

最佳答案

我收到此错误是因为我使用的是旧 Node 版本 (8.17.0),将 Node 更新到较新版本 (12.14.0) 修复了此错误。

关于javascript - TypeError [ERR_INVALID_ARG_TYPE] : The "original" argument must be of type Function. 接收类型未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56136805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com