[英]Why am getting this error TypeError: Cannot read property 'client' of undefined
if (arguments.length === 0 || !config.client && !config.dialect) {
^
TypeError: Cannot read property 'client' of undefined
类型错误:无法读取未定义的属性“客户端”
Why am I getting this error?为什么我收到这个错误?
The config
variable is undefined
. config
变量是undefined
。 You should check it to before reading the values of config.client
and config.dialect
你应该在阅读
config.client
和config.dialect
的值之前检查它
if (arguments.length === 0 || (config && !config.client && !config.dialect))
Keep in minds that if config is undefined
, the evaluation of the right expression in the OR
clause will be false请记住,如果 config
undefined
,则OR
子句中正确表达式的计算结果将为 false
I was running into this issue as well.我也遇到了这个问题。 In my code I'm initializing knex in the following way.
在我的代码中,我按以下方式初始化 knex。
const knex = require('knex')(process.env.DATABASE_URL)
When I checked the value of process.env.DATABASE_URL
I discovered that it was undefined.当我检查
process.env.DATABASE_URL
的值时,我发现它是未定义的。 Once I fixed that, the error went away!一旦我解决了这个问题,错误就消失了! (In my case I had my .env file in the wrong place)
(就我而言,我的 .env 文件放错了地方)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.