Static GitHub Issues

[757] Proper way to create a store

prev: npm link packageName does not work when using nuxt
next: Strip comments from produced code in production mode.

Me and my counterpart are working on the same project. And today we encountered a peculiar issue.

I'm sitting on MacOS with Node 7.10, and I have instantiated store this way:

const store = {
  state: { data: [] },
  mutations: {
    addData: state => payload => state.data.unshift(...payload)
  }
}

export default store

And everything works as intended. Even without importing and instantiating Vuex.

While my counterpart, on Ubuntu 16.10 with Node 7.7.6, gets an error with the same setting.

Nuxt.js Error:

Error: [nuxt] store/index.js should export a method which returns a Vuex instance.
    at getModule (.nuxt/store.js:53:10)
    at Object.module.exports.Object.defineProperty.value (.nuxt/store.js:16:14)

When in attempt to fix the issue I red an official example, and, instead of store object, I made a function which returns new store instance as example suggests:

import Vuex from 'vuex'

const store = () => {
  return new Vuex.Store({
    state: { data: [] },
    mutations: {
      addData: state => payload => state.data.unshift(...payload)
  })
}

export default store

The real fun begun here. The 'official' way does not work on my machine and causes store to be undefined.

I'm so much confused, I'd be very glad if anyone explain me what is going on.

Thank you in advance!

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c647">#c647</a>)</em></sub></div>