1

I'm trying to use the mapActions in Vuex as given in Vuex Actions

methods:{
            ...mapActions([
                'increment' // map this.increment() to this.$store.dispatch('increment')
            ])
}

But, it is giving me SyntaxError: Unexpected token at ... . I'm not sure what the problem is and what details I would need to include in the question.

jaysingkar
  • 4,315
  • 1
  • 18
  • 26

2 Answers2

2

Try adding this to your package.json

"eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module",
      "ecmaFeatures": {
        "jsx": true,
        "modules": true,
        "experimentalObjectRestSpread": true
      },
      "env": {
        "es6": true,
        "browser": true
      }
    }
  }

and in your gulp file in your laravel-elixir instance check if there's a transformer named babelify in elixir.config.js.browserify.transformers and if it exists push into its options.presets a string stage-2. Here's how I have it in my gulp file:

var elixir = require('laravel-elixir')    
if (elixir.config.js.browserify.transformers[0].name === 'babelify') {
        elixir.config.js.browserify.transformers[0].options.presets.push('stage-2');
    }

It may differ for you but you get the idea. All this makes browserify compile the assets using the stage-2 features like the object spread operator that wouldn't normally be contemplated.

António Quadrado
  • 1,307
  • 2
  • 17
  • 34
2

1:Install the label plugin:

npm install --save-dev babel-plugin-transform-object-rest-spread

2:Then fix the .babelrc file as follow:

{
    "presets": [["latest", {"es2015": { "modules": false }}]],
    "plugins": ["transform-object-rest-spread"]
}
Aaron
  • 387
  • 3
  • 3