Roots Discourse

Using async throws “unexpected token”

Hey I was trying to use async in my project but the I got an error when the code compiled.

Module build failed:
113 :
114 :   actions: {
115 :
116 :     // This Updates the Product Listing
117 :      async function getProducts({commit}) {
                 ^
Unexpected token (117:11)

This is once of my vuex store action.

I found this closed query,

It seems we don’t have the fix for it. Does any one know any workaround for this ?

UPDATE

Is there a way this can be bypassed by disabling it for this particular file.

I saw a solution for it here.

Which says to use.

transforms: {
  generator: false
}

which would not fail buble. But this resulted in braking of other codes.

I added this in my webpack.config.js file.

        test: /\.js$/,
        exclude: [/node_modules(?![/|\\](bootstrap|foundation-sites))/],
        use: [
          { loader: 'cache' },
          { loader: 'buble', options: {
            objectAssign: 'Object.assign',
              ////////// This was added
              transforms: {
                generator: false,
              },
            ////////////////
            } },
        ],

this resulted into.


 ERROR  Failed to compile with 4 errors                                                                                                                                                               21:52:20

Module build failed:
1 : import '../partials/header';
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
import is not supported (1:0)

Module build failed:
22 : //
23 :
24 :
25 :
26 : import Vue from 'vue';
     ^^^^^^^^^^^^^^^^^^^^^^
import is not supported (26:0)

Module build failed:
29 : //
30 : //
31 :
32 : // import SimpleProductCard from '../SimpleProductCard.vue';
33 : import CategorySearchFilters from './CategorySearchFilters.vue';
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
import is not supported (33:0)

Module build failed:
7  : //
8  : //
9  : //
10 :
11 : import LookbookNodes from './LookbookNodes.vue';
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
import is not supported (11:0)