无法读取未定义的属性“交易”

时间:2018-12-17 11:32:33

标签: knex.js bookshelf.js

我将knex更新为版本0.16.2,书架为0.14.1,但是当我在书架中使用事务时:

     return  bookshelf.transaction(async function(trx) {
       ... code here
     }

我收到以下错误消息:

TypeError: Cannot read property 'transaction' of undefined
    at Object.transaction (/Users/abc/Desktop/proj/backend/node_modules/knex/lib/util/make-knex.js:56:31)
    at Object.transaction (/Users/abc/Desktop/proj/backend/node_modules/bookshelf/lib/bookshelf.js:249:36)
    at Function.addAction (/Users/abc/Desktop/proj/backend/models/User.js:180:30)

问题是

const trx = this.client.transaction(container, config); 

在node_modules / knex / lib / util / make-knex.js:56:31中,因为this.client返回未定义

,由调用:

transaction: function transaction() {
      return this.knex.transaction.apply(this, arguments);
 },

在node_modules / bookshelf / lib / bookshelf.js:24

基本上,我们的bookhelf.client返回undefined。不确定如何解决此问题。

1 个答案:

答案 0 :(得分:1)

这在书架0.14.2中已得到修复:https://github.com/bookshelf/bookshelf/releases/tag/0.14.2