question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"...mapActions" Unexpected token

See original GitHub issue

I have a Vue component that is trying to use:

Register.vue

<script>
import { mapActions } from 'vuex'

// ...

methods: {
    // ...
    ...mapActions({
        storeDetails: 'updateRegisterDetails'
    })
}

// ...
</script>

However, when I run yarn run dev I get the following output:

 ERROR  Failed to compile with 1 errors

 error  in ./resources/assets/js/auth/components/Register.vue

SyntaxError: Unexpected token (54:8)

  52 |             this.$router.push('/register/payment')
  53 |         },
> 54 |         ...mapActions({
     |         ^
  55 |             storeDetails: 'updateRegisterDetails'
  56 |         })
  57 |     }



 @ ./resources/assets/js/auth/components/Register.vue 3:2-131
 @ ./resources/assets/js/auth/routes.js
 @ ./resources/assets/js/auth.js
 @ multi ./resources/assets/js/auth.js

                                Asset       Size  Chunks                    Chunk Names
     /js/auth.51d4dde1906cc579aad7.js    2.22 MB       0  [emitted]  [big]  /js/auth
      /js/app.ecd4f96976599fef6161.js    2.18 MB       1  [emitted]  [big]  /js/app
    /css/app.8598eae19ab06ab7bf2b.css     177 kB       1  [emitted]         /js/app
 /js/auth.51d4dde1906cc579aad7.js.map    2.74 MB       0  [emitted]         /js/auth
  /js/app.ecd4f96976599fef6161.js.map    2.68 MB       1  [emitted]         /js/app
/css/app.8598eae19ab06ab7bf2b.css.map    10.3 kB       1  [emitted]         /js/app
                    mix-manifest.json  344 bytes          [emitted]
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Any idea what I should be doing here? I don’t see anything documented in regards to configuring anything additional for Vue.

webpack.mix.js

const { mix } = require('laravel-mix');

if (process.env.NODE_ENV == 'production') {
    mix.disableNotifications();
}

mix.webpackConfig({
    devtool: 'cheap-source-map'
});

mix.js('resources/assets/js/app.js', 'public/js')
   .js('resources/assets/js/auth.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css')
   .version(['css/app.css', 'js/app.js', 'js/auth.js']);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

46reactions
ellisiocommented, Feb 8, 2017

Running the following:

yarn add --dev babel-preset-es2015 babel-preset-stage-2

Then creating a .babelrc in the root of our project with:

{
    "presets": ["es2015", "stage-2"]
}

Resolved this.

23reactions
yunhan0commented, Mar 8, 2018

Don’t have to install babel-preset-stage-2, simply add Object rest spread transform babel plugin.

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

in .babelrc, add the following: { "plugins": ["transform-object-rest-spread"] }

Read more comments on GitHub >

github_iconTop Results From Across the Web

"...mapActions" Unexpected token · Issue #345 · laravel-mix ...
I have a Vue component that is trying to use: Register.vue However, when I run yarn run dev I...
Read more >
Unexpected token when I trying to use ...mapGetters or ...
I try to follow the nuxt guide, but I can't find nothing about how to use mapGetters. This is the shell error: Syntax...
Read more >
'Unexpected token' when using mapState - Vue Forum
My babel config is set to es2015 so I guess that's why the spread operator doesn't work, but that doesn't explain my second...
Read more >
Vuex : error ...mapActions ...mapGetters - Laracasts
I have an error. Copy Code error in ./resources/assets/js/components/Searchbar.vue Syntax Error: Unexpected token (102:8). from this code. Copy Code
Read more >
vuex2中使用mapMutations/mapActions报错解决方法 ... - 博客园
但是在借助babel编译转换时发生了报错: BabelLoaderError: SyntaxError: Unexpected token 。 解决方案在vuex的repo issues中有人提过这样的问题,后来是 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found