SyntaxError: Unexpected token 'const' (with Vue, Karma, Webpack, PhantomJS)

前端 未结 3 971
天命终不由人
天命终不由人 2020-12-18 01:28

I have a more-or-less vanilla Laravel + Vue.js app and I am trying to do some JS testing with Karma and Jasmine. If I try to use () => {} style functions or

3条回答
  •  不思量自难忘°
    2020-12-18 01:42

    I had a similar problem (though not identical; your configuration is pretty specific). I was also using Vue, karma, webpack, and phantomjs (as configured in the vue-Webpack template).

    However, my problem is that I was defining const in a helper file that was getting imported into my app. When I changed const to var in that file, the tests were able to run.(It didn't matter whether or not const was used in other files that were already within the src directory).

    This problem was fixed when I moved this helper file into my src folder or one of its subdirectories. I'm too much of a novice to know why this solved the problem, but I'm guessing that babel wasn't configured to work in the root folder, and was only pointed towards the src folder.

    Hopefully this is helpful for others as well.

提交回复
热议问题