"Error: [vuex] actions should be function or object with "handler" function but "actions.default" is {}" after updating Vue & Vuex

"Error: [vuex] actions should be function or object with "handler" function but "actions.default" is {}" after updating Vue & Vuex

我对我的项目进行了以下 npm 包更新:

vuex: 2.3.1 -> 3.0.0
vue: 2.4.2 -> 2.5.2
vue-router: 2.7.0 -> 3.0.1

(还有一些,但我认为它们与这个问题无关)

现在我在启动我的网页时遇到了这个错误:

Error: [vuex] actions should be function or object with "handler" function but "actions.default" is {}

我不太确定为什么,我阅读了 Vuex 变更日志,语法似乎并没有真正改变,但由于某种原因我的代码崩溃了。

仔细检查这个问题后,我发现该错误是由名为 vuex.esm.js:

的文件中的失败断言引起的
function assert (condition, msg) {
    if (!condition) { throw new Error(("[vuex] " + msg)) }
}

代码在更新包之前工作正常,我可能在这里遗漏了一些东西。我很乐意提供任何可能有助于更好地理解问题的代码。

谢谢!

编辑: 这是导致错误的调用堆栈:

我在单元测试中遇到了同样的错误。我刚刚在我的操作中添加了一个空的 handler 函数,然后它就起作用了...

const state = { auth: { authenticated: false } };
const actions = { auth: { handler: () => {}, logout: () => sinon.stub() } };
let store;
beforeEach(() => {
   store = new Vuex.Store({
     state,
     actions,
   });
});