【问题标题】:Cannot read property 'transaction' of undefined无法读取未定义的属性“事务”
【发布时间】:2023-03-26 16:40:01
【问题描述】:

我将 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 返回 undefined

由 :

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

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

基本上我们的 bookshelf.client 返回 undefined。不知道如何解决这个问题。

【问题讨论】:

  • 如果我将 knex 降级到 0.14.6(我以前的版本),我就能让它工作
  • 是的,Bookshelf 还不兼容 knex 0.15+。
  • @devius : 知道书架何时能与最新版本的 knex 兼容。

标签: knex.js bookshelf.js


【解决方案1】:

这刚刚在 Bookshelf 0.14.2 中修复:https://github.com/bookshelf/bookshelf/releases/tag/0.14.2

【讨论】:

猜你喜欢
  • 2019-05-23
  • 2020-11-18
  • 2021-12-14
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多