Home > OS >  vue-cli-service test:unit trigger an "Unexpected token" on `...` (spread operator)
vue-cli-service test:unit trigger an "Unexpected token" on `...` (spread operator)

Time:09-24

on my code i'm using ... (destructure operator). but i got "Unexpected token" on module build phase, i don't know how to fix this issue ? (beside rewrite my code in a way without using ... operator)

i use vue-cli-service test:unit src/**/*.spec.js to run tests,

package.json:

    ...
    "devDependencies": {
        "@vue/cli-plugin-babel": "^3.12.1",
        "@vue/cli-service": "^4.5.9",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-cli": "^6.26.0",
        ...
    },
    ...

enter image description here

CodePudding user response:

To fix this problem i've needed to install @babel/preset-env and set it on babel.config.js (in my case) or .babelrc

presets: [
    [
        '@babel/preset-env',
        {
            targets: {
                esmodules: true,
            },
        }
    ]
],

source of solution is this github comment

also targets.esmodules in depth

  • Related