Nuxt plugin not available in Vuex's 'this' in Firebase production (ERROR: this.$myPlugin is not a function)

Nuxt plugin not available in Vuex's 'this' in Firebase production (ERROR: this.$myPlugin is not a function)

我正在尝试将我的 nuxt 应用作为云功能上传到 Firebase。问题是,在 nuxtServerInit 操作中,我试图调用一个 plugin 函数,该函数显然当时尚未定义,因为抛出了一个错误:(ERROR: this.$myPlugin is not a function)。代码在开发模式下工作,只是在上传到Firebase后失败。

设置如下:

myPlugin.js

let env, auth, app, $store;
export default (context, inject) => {
    env = context.app.context.env;
    auth = context.app.$fire.auth;
    app = context.app;
    $store = context.store;
    inject('myPlugin', myPlugin);
};
async function myPlugin(...) {... }

nuxt.config.js

plugins: [
    { src: '~/plugins/myPlugin', mode: 'all' }, // with no mode specified it fails too
],

vuex index.js

export const actions = {
    async nuxtServerInit({ dispatch, commit }, { req }) { 
        const tl = await dispatch("initAction");
        return tl;
    }
}

vuex someModule.js

const actions = {
    initAction({ commit }) {
        return this.$myPlugin(...).then(...) // this line throws '$myPlugin is not a function' error
    }
}

devprod 模式下行为不同的原因是什么?我该如何解决这个问题?

更新: 经过进一步测试,我确定问题不是由 nuxtServerInit 时间引起的。我将 initAction 的调用从 nuxtServerInit 移至页面的 created 挂钩。但是出现同样的错误:this.$query is not a function.

问题出现了,因为配置不正确导致CORB错误导致js文件没有完全加载。 .

中描述的详细信息