Categories: Javascript

vuex-module-decoratorsを使っているとERR_STORE_NOT_PROVIDEDが出る件の解消法

@Actionを記載したstoreのメソッドを呼び出そうとしたら下記エラーが出た。
Uncaught (in promise) Error: ERR_STORE_NOT_PROVIDED: To use getModule(), either the module
should be decorated with store in decorator, i.e. @Module({store: store}) or
store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)
さっぱり原因がわからなかったのですがようやく解決できたのでそのメモ。

構成と症状

NuxtとTypescriptによる環境で、ストアに関しては、Nuxtのストアのvuex-module-decorators によるアプローチの構成をそのまま使用していました。
initialiseStoresで@Actionのメソッドを呼び出すことは問題なくできたのですが、page側で呼び出すと本件のエラーが発生しました。
しかし、新規プロジェクトでまっさらに組むとこの問題が発生しないのです。
そのため、別途インストールしたライブラリがなんか悪さしてるのではないかと感じました。

解決方法

私の読みはあたり、nuxt-i18nをmodulesに追加してると本エラーが発生してるようでした。
しかし、ローカライズにも使っているのでこの子を外すわけにもいきません。
はてさてどうしたもんかとドキュメントを漁っていたらvuex: falseというオプションがあることを発見したので、いれてみたら見事解決しました!

nuxt.config.ts抜粋
  i18n: {
    locales: [
      {
        code: 'ja',
        iso: 'ja-JP',
        name: '日本語',
        file: 'ja.json'
      }
    ],
    defaultLocale: 'ja',
    strategy: 'no_prefix',
    lazy: true,
    langDir: 'locales/lang/',
    vueI18n: {
      fallbackLocale: 'ja'
    },
    vueI18nLoader: true,
    vuex: false // ←これいれた
  },

まとめ

おそらくあとからVuexが使われたりすると競合しちゃうんでしょうね。 他のライブラリとかでももしかすると兼ね合いで発生するかもしれないので参考になればと思います。
mogmet

View Comments

  • Your article helped me a lot, is there any more related content? Thanks!

  • Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  • Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  • Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  • Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  • The game library here keeps growing and I love how easy it is to find exactly what I am in the mood for. Customer service responded to my message within minutes and walked me through the bonus steps clearly. Every round loads smoothly and my balance updates instantly. A solid pick for anyone who values fair play and smooth navigation. mxjogocasino

  • I was a bit skeptical at first but this platform won me over with its rock solid performance. No sudden crashes during important rounds and the support crew is always patient and polite. The game roster has something for every mood and budget without feeling overwhelming. A refreshing spot in a crowded market that truly respects its players. 2777dblogin

  • Finally a platform that truly understands what Filipino players enjoy. The local payment options make deposits a breeze and the live dealer games capture that vibrant energy we love. I always recommend it to my friends because the experience stays consistent and genuinely fun. 55jili

Share
Published by
mogmet