【发布时间】:2020-12-15 19:25:12
【问题描述】:
我在尝试将配置导出为异步函数时遇到了 knex 问题。
我的 knex 文件是:
async function fetchConfiguration() {
return {
staging:{
client: 'mysql',
connection: {
host : 'dbIp',
user : 'user',
password : 'password',
database : 'myDatabase'
}
}
}
}
module.exports = async () => {
const configuration = await fetchConfiguration();
return {
...configuration
}
};
我的 connection.js 是:
const knex = require('knex');
const configuration = require('../../knexfile');
var connection = knex(configuration.staging);
module.exports = connection;
但是在运行时,我得到了这个错误
C:\Users\fabio\Documents\Projetos_CVC\uptime\uptime\API\node_modules\knex\lib\knex.js:22
if (arguments.length === 0 || (!config.client && !config.dialect)) {
^
TypeError: Cannot read property 'client' of undefined
at Knex (C:\Users\fabio\Documents\Projetos_CVC\uptime\uptime\API\node_modules\knex\lib\knex.js:22:42)
at Object.<anonymous> (C:\Users\fabio\Documents\Projetos_CVC\uptime\uptime\API\src\database\connection.js:4:18)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\fabio\Documents\Projetos_CVC\uptime\uptime\API\src\controllers\CheckController.js:1:20)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
很快我就需要在这个项目中使用 vault 和 consul,所以不使用异步创建很复杂。 感谢您对此提供的任何帮助。
【问题讨论】:
标签: javascript node.js knex.js async.js hashicorp-vault